set a timer in workflow based on a variable

Jan-Z
Giga Expert

Is it possible to create a workflow timer based on a variable date?


The termination date is defined as a date type in the variable set. I would like to put a timer in the workflow to send a task to the HR dept 14 days before the termination date.

I don't know if I can create a timer in a workflow based on a variable.

10 REPLIES 10

tgryziec
Mega Contributor

I know you probably don't want to script but I did the work for you :). Just replace *insertName* with your variable name you should be good to go. I have also provided links on the wiki.
http://wiki.servicenow.com/index.php?title=GlideSystem_Date_and_Time_Functions#daysAgo.28int.29
http://wiki.servicenow.com/index.php?title=GlideSystem_Date_and_Time_Functions#dateDiff.28String.2C_String.2C_boolean.29
http://wiki.servicenow.com/index.php?title=GlideSystem_Date_and_Time_Functions#nowNoTZ.28.29

//Put catalog variable in easy to read variable. You will want to replace *insertName* with the variable name.
var dateTime = current.variables.*insertName*;
//Count back two weeks from date entered.
var twoWeekearly = dateTime.daysAgo(14);
//Find the difference between now and when HR should be notified in seconds.
var seconds = gs.dateDiff(gs.nowNoTZ(), twoWeekearly, 1);
//Return the answer to the timer activity to wait that many seconds.
answer = seconds;


If you want to script tgryziec's script will work. Thanks!


This doesn't appear to work for me

find_real_file.png

find_real_file.png

Do you see Line No 4 Correct?

gs.noNoTZ()

Jan-Z
Giga Expert

Thank you both.

I tried the script but it did not work. The task was created immediately.
the variable containing the term date is called "end"

it is part of a variable set. would that change the script at all?

I included screenshots of the workflow and the timer.