I believe the answer probably lies somewhere within a script but I would like to create a checklist item in an automation, and set the due date to be X days out but have those X days be weekdays only. Looks like I should be able to do this from the calc option within the automation action?
Hi @joelhall,
also from my side a warm welcome to the Tape community
Thanks for sharing your use case. This sounds like a great real world case.
As Tape uses standard JavaScript, a great option to generate such code is ChatGPT. I used this prompt:
Write a javascript function that adds n days to the current day, but if the result is a weekend moves forward to the next weekday.
The result looks as follows (just tweaked it a little to match the Tape variable later):
function addBusinessDays(n) {
const currentDate = new Date();
let dayCount = 0;
while (dayCount < n) {
currentDate.setDate(currentDate.getDate() + 1);
// Check if the current day is a weekend (Saturday or Sunday)
if (currentDate.getDay() === 0 || currentDate.getDay() === 6) {
continue; // Skip weekends
}
dayCount++;
}
return currentDate;
}
// Example usage:
const n = 5; // Add 5 business days; n=1 would be the next business day after today.
const new_date = addBusinessDays(n);
console.log(new_date);
var_next_due_date = new_date
After putting this in an “Execute Script” action, you can use the variable to add your checklist entry:
It should then generate the desired result:
I hope that works for you. Let me know how it goes!
Happy scripting & Cheers
Tim
@Tim yes! That worked perfect. I had something very close in GPT (my prompt creation needs some work ). I was trying to place the script in the due date calculation field itself rather than using the “Execute Script” to create a variable action. Now it makes sense as this is like setting a variable action in Podio Workflow Automation and then using that variable later on. Thank you for the guidance.