Generate a task based on a specific variable date

Cupcake
Mega Guru

I want to know if it is possible to generate a task based on the date of a variable. If this is not feasible or there are many risks, could someone offer a solution based on this need.

So I have a catalog item that has a variable that is a date field. The way that I want this workflow to work is:

a. Customer submits the form,

b. All approvals go through,

c. An email goes to the customer letting them know that the access has been granted.

d. Once all tasks have been completed, I want the workflow to stop & wait but not close the RITM because the variable that is a date field I want a task to generate when that date has been reached

find_real_file.png

find_real_file.png

 

Any assistance would be much appreciated.

Thank you,

Karen

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

You can do something like below. add timer after wait for task timer

Timer

Name: Wait for End date

Time based on: Script

Script:

var endDate = current.variables.end.getDisplayValue();
answer = gs.dateDiff(gs.nowDateTime(), endDate, true);

View solution in original post

15 REPLIES 15

You are welcome Karen.

 

I applaud your approach of leveraging the community and doing your research to find out *IF* it can be done and *WHAT* it will take to do it before saying "Sure!" and getting stuck with "Now, how do I do this?" only to find out it's a deep customization that will haunt someone for the rest of their ServiceNow life. 🙂

 

Good job!

Hi @Chuck Tomasi 

 

Great thanks for your response,

I have also same kind of requirement but the timer should exclude 'weekdays and holidays'. Can you please help me following requirement.

 

Requirement 1 : We have a variable called 'Expiration Date'. If expiration date is -7 days send a email notification to requested for. 

 

Script in Timer activity :

var powerDownDateTime = current.variables.expiration_date;
var diffSeconds = gs.dateDiff(gs.nowDateTime(), powerDownDateTime, true);
answer = (diffSeconds - 214200); // -7 days

 

Requirement 2: If 'expiration date' is today, create a catalog task by tomorrow morning at 6 AM.

Script in Timer activity :

var powerDownDateTime = current.variables.expiration_date;
var diffSeconds = gs.dateDiff(gs.nowDateTime(), powerDownDateTime, true);
answer = (diffSeconds + 30600); // +1 day
 
ManiPolisetty2_0-1707227000269.png

 

Thanks

Mani Polisetty

Eric K3
Kilo Guru

I had to do the following to make the timer work for me, using date/time from a variable:

 

// Set 'answer' to the number of seconds this timer should wait
var powerDownDateTime = current.variables.srvr_req_decom_power_down;
var diffSeconds = gs.dateDiff(gs.nowDateTime(), powerDownDateTime, true);

answer = (diffSeconds - 18000);

 

I do not know why I had to subtract the 5 hours to make this work. Is the timezone wrong on my instance?

Yes, By default all date/time are stored in UTC.

 

https://docs.servicenow.com/bundle/jakarta-platform-administration/page/administer/time/reference/r_TimeZones.html

add something like .getLocalTime() to get localtime