We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

How to build a delay in a workflow for task creation

MBMRED
Tera Expert

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:

  1. 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)
  2. 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

1 ACCEPTED SOLUTION

Tanushree Maiti
Tera Patron

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/i-need-to-schedule-an-email-notifications-for-c...

 https://www.servicenow.com/community/developer-forum/workflow-timer-activity-script/td-p/3463501

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

View solution in original post

6 REPLIES 6

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,

 

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.