New RegEx matching
I replaced the existing matches regex
case in the checkCondition()
function with:
case "matches regex":
try {
let regex = new RegExp(conditionValue, "i"); // Case insensitive match
return regex.test(String(value));
} catch (e) {
throw new Error(`Invalid regex: "${conditionValue}"`);
}
Worked better at matching for me, and also gives errors if you mess up the regex.
Date to last day of month
This may be me-specific, but I added another case for the performAction()
function. It takes a date field and changes it to be the first of the next month if it is at the end of the month. This makes it easier for me to budget income and makes my paycheck and my wife’s paycheck virtually pay us on the same day.
case "adjust date to first of next month":
const oldDate = new Date(rowData[column]); // Get the existing date
const lastDayOfMonth = new Date(oldDate.getFullYear(), oldDate.getMonth() + 1, 0).getDate();
if (oldDate.getDate() > lastDayOfMonth - 5) {
// If within the last 5 days, set to the 1st of next month
const newDate = new Date(oldDate.getFullYear(), oldDate.getMonth() + 1, 1);
yap(`Adjusting date for row ${rowNum} to ${newDate.toISOString().slice(0, 10)}`);
r.setValue(newDate);
}
break;
I just leave the ‘Action Value’ blank when that is selected as the ‘Action.’