Cheklist Date Calculation

Hi all, I have a checklist where by default very firt is assigned and next one is assigned when the cirrent is marked as completed…I am getting the next checklistitem name correctly but the issue is not getting the correct date for example for ‘week 1’ I want to add 7 days and when the existing one is marked as completed then ‘week 1’ should be assigned with 7 days added i.e. if previous marked on 31 then adding 7 days to 31 should give the next month’s 7…
below is the script I’m struggling for getting correctDate. @Jason if you could help?

// Complete checklist with intervals between sequential steps
let nextChkLstItem = “”;
let nextchecklistItmDate = null;

if (var_checklist == “Congratulate the new Recruit”) {
nextChkLstItem = “Week 1 Check-in - Phone Call”;
let nextDate = new Date(); // Today (when this step is completed)
nextDate.setDate(nextDate.getDate() + 7); // Week 1 in 7 days
nextchecklistItmDate = nextDate;
}
else if (var_checklist == “Week 1 Check-in - Phone Call”) {
nextChkLstItem = “Week 2 Check-in - Phone Call”;
let nextDate = new Date(); // Today (when Week 1 is completed)
nextDate.setDate(nextDate.getDate() + 7); // Week 2 in 7 days from Week 1
nextchecklistItmDate = nextDate;
}
else if (var_checklist == “Week 2 Check-in - Phone Call”) {
nextChkLstItem = “Week 3 Check-in - Phone Call”;
let nextDate = new Date(); // Today (when Week 2 is completed)
nextDate.setDate(nextDate.getDate() + 7); // Week 3 in 7 days from Week 2
nextchecklistItmDate = nextDate;
}
else if (var_checklist == “Week 3 Check-in - Phone Call”) {
nextChkLstItem = “1 Month Check-in - Phone Call”;
let nextDate = new Date(); // Today (when Week 3 is completed)
nextDate.setDate(nextDate.getDate() + 7); // 1 month check in 7 days from Week 3 (total ~30 days from start)
nextchecklistItmDate = nextDate;
}
else if (var_checklist == “1 Month Check-in - Phone Call”) {
nextChkLstItem = “Month 2 Check-in - Phone Call”;
let nextDate = new Date(); // Today (when 1 month is completed)
nextDate.setDate(nextDate.getDate() + 30); // Month 2 in 30 days from Month 1
nextchecklistItmDate = nextDate;
}
else if (var_checklist == “Month 2 Check-in - Phone Call”) {
nextChkLstItem = “1st Qtr Check-in - Phone Call”;
let nextDate = new Date(); // Today (when Month 2 is completed)
nextDate.setDate(nextDate.getDate() + 30); // 1st Quarter in 30 days from Month 2 (total ~90 days)
nextchecklistItmDate = nextDate;
}
else if (var_checklist == “1st Qtr Check-in - Phone Call”) {
nextChkLstItem = “2nd Qtr Check-in - Phone Call”;
let nextDate = new Date(); // Today (when 1st Quarter is completed)
nextDate.setDate(nextDate.getDate() + 90); // 2nd Quarter in 90 days from 1st Quarter (total ~180 days)
nextchecklistItmDate = nextDate;
}
else if (var_checklist == “2nd Qtr Check-in - Phone Call”) {
nextChkLstItem = “3rd Qtr Check-in - Phone Call”;
let nextDate = new Date(); // Today (when 2nd Quarter is completed)
nextDate.setDate(nextDate.getDate() + 90); // 3rd Quarter in 90 days from 2nd Quarter (total ~270 days)
nextchecklistItmDate = nextDate;
}
else if (var_checklist == “3rd Qtr Check-in - Phone Call”) {
nextChkLstItem = “1 Year Anniversary Check-in - Phone Call”;
let nextDate = new Date(); // Today (when 3rd Quarter is completed)
nextDate.setDate(nextDate.getDate() + 90); // 1 Year Anniversary in 90 days from 3rd Quarter (total ~365 days)
nextchecklistItmDate = nextDate;
}
else if (var_checklist == “1 Year Anniversary Check-in - Phone Call”) {
nextChkLstItem = “Completed - No more steps”;
nextchecklistItmDate = null; // No more future dates needed
}
else {
nextChkLstItem = “Unknown”;
nextchecklistItmDate = new Date();
}

// Return the result
var_nextchecklistitemdate = nextchecklistItmDate ? nextchecklistItmDate.toISOString().split(‘T’)[0] : null

This currently runs when a checklist item is completed, right?

Looks like it runs [today] + n days

What is the issue you’re running into?

The issue was just a minor but as a newbie, it took me some hours to resolve this…it was not updating the date first and then the correct date…Just added the current_date_local and it worked fine

1 Like

Awesome!

Thanks for sharing with the community so it can help someone else in the future.

1 Like