- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I'm looking for advice on how to build a delay into a workflow (using Workflow Studio) to create tasks relative to a specific date.
Scenario:
Create tasks 60-days prior to indicated start date (captured in the requested item).
Caveat: Start date may change while we're waiting on tasks to kick off.
Requirements:
- Periodically check the "start date" on the RITM to determine if the start date has changed.
- If changed, the delay loop should auto-adjust to the new date (forward or backward)
- Best way to delay task creation until today's date is at/within 60-days of start date
Note: We are on Zurich.
Thank you in advance,
Mathew
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @MBMRED
The best way to delay task creation until 60 days before a start date in a workflow is to use a Timer activity configured with a custom script. This script dynamically calculates the exact difference in seconds between today's date and the target start date minus 60 days, pausing the workflow until then.
In Timer activity ->Script
(sample script /not tested/ modify it as per your requirement)
var startDate = new GlideDateTime(current.variables.u_start_date);
startDate.addDaysUTC(-60);
var now = new GlideDateTime();
var diffSeconds = (startDate.getNumericValue() - now.getNumericValue()) / 1000;
if (diffSeconds < 0) {
answer = 0;
} else {
answer = diffSeconds;
}
Refer:
https://www.servicenow.com/community/developer-forum/workflow-timer-activity-script/td-p/3463501
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @MBMRED
The best way to delay task creation until 60 days before a start date in a workflow is to use a Timer activity configured with a custom script. This script dynamically calculates the exact difference in seconds between today's date and the target start date minus 60 days, pausing the workflow until then.
In Timer activity ->Script
(sample script /not tested/ modify it as per your requirement)
var startDate = new GlideDateTime(current.variables.u_start_date);
startDate.addDaysUTC(-60);
var now = new GlideDateTime();
var diffSeconds = (startDate.getNumericValue() - now.getNumericValue()) / 1000;
if (diffSeconds < 0) {
answer = 0;
} else {
answer = diffSeconds;
}
Refer:
https://www.servicenow.com/community/developer-forum/workflow-timer-activity-script/td-p/3463501
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
see this link
Create Catalog task after 30 days from the selected date in variable
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Ankur,
Will this periodically check the RITM to verify that the "Start Date" (that is the reference date) has not changed?
Thank you,
Mathew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Setting flow designer flows and workflow execution to wait for longer times might break over a long run.
This seems to be problem that should be solved process wise instead of technical.
Eitherway, I had similiar topics in the past and we went with creating the tasks/records without waiting but putting it's due date to the desired date. This works for employee task's, because the 'My Task' widget in the portal is sorting by due date by default. The task is created, sorted to the bottom and you do not have to think about making the workflow wait for time x.
If this is about sc_tasks, please reconsinder creating them outside of the flow attached to the sc_cat_item because you'd have to make the sc_cat_item's flow aware, that a catalog task was created outside of the flow in case that the flow should wait for the task to be closed.