Scheduled Recurring Tasks

hartr
Giga Contributor

I have a requirement to create recurring future tasks for a client. I can use scheduled templates to create the records, but have two issues that I hope someone can help with.

1) How to set a glide_date field with a future repeating date within the template (gs.daysAgo(-x)) doesn't work.
2) How to schedule the recurrence for a specific weekday in the month (e.g. First Monday of every month)

Would appreciate any help from anyone who has created something similar.

5 REPLIES 5

jacob_kimball
ServiceNow Employee
ServiceNow Employee

Here is some specific code that I used addWeeks/addMonths in that might be of use:



// Get a date from the table and covert it to a GlideObject
var startDateMod = current.u_start_date.getGlideObject();

// Some logic used to tell if we need to add months or weeks to the original start date.
if(newDateInc > 0)
startDateMod.addMonths(1); //Monthly based calculation: Annually, monthly, quarterly
else
startDateMod.addWeeks(1); //Weekly based calculation: weekly


Obviously some context missing here, but basically I grab the date from a table and make (cast?) a GlideObject out of it. From there the addMonths/Weeks/Days seems to work as advertised. I believe I have even used negative values in there to get times in the past.

If that doesn't help any, perhaps shoot some code in here of what you are trying to do and that might help to figure out where things are going south.