- 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
2 weeks ago
Luca,
Thank you for the advice. In our situation, the request is tied to when a coworker will join our organization, which is the referenced "start date". This date can be 2 weeks from when the RITM is submitted or 12 months.
I understand and agree that longer "timers" in a workflow can lead to issues, but we don't have a choice on this one.
We need the timer to watch the RITM to ensure the date has not changed and if the date is within 60 days, then tasks need to fire.
Thank you,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
One more idea could be to only start the process x days before the actual start date.
We had a smiliar situation where people would join on day x. Several days before day x, they would already be within AD / known in the identity management systems and provisioned to SN. Only x days before the start date, we would submit the needed cat items to trigger the onboarding.