Workflow Timer Script Example

elemonnier
Tera Expert

You can never get enough examples, so I've included a small example of a workflow timer that pulls a Catalog Item form variable and calculates a time to wait from that date.



//get term_datetime variable
var termDate = new GlideDateTime();
termDate.setDisplayValue(current.variable_pool.term_datetime.getDisplayValue());

//convert to millisecond value and add specified time
var termDateValue = termDate.getNumericValue()
termDateValue += (1000*60*60*24*30); //Add 30 days

//write offset time to datetime variable
var offsetDate = new GlideDateTime();
offsetDate.setNumericValue(termDateValue);
//write comments to RITM
current.comments = '"Additional task on hold until: ' + offsetDate.getDisplayValue();
//return difference from current time to offset time in secs
answer = gs.dateDiff(gs.nowDateTime(),offsetDate.getDisplayValue(),true);
5 REPLIES 5

Markell
Tera Guru

HiGuys

 

I tried to do a variation of this script to set the timer to run 14 days after the Open_at date.

Although I have found an easier way to do that specific solution via the "Timer based on", I have further utilized the script else where.

 

The script seemed to be working because the timer was activated:

find_real_file.png

 

Which it was not doing before.

 

What happens now though is the work flow does not progress any further after that point it is just stuck on "Running".

 

The code I used is below:

 

var reqDate = new GlideDateTime();
reqDate.setDisplayValue(current.sys_created_on.getDisplayValue());

//convert date value to millisecond value
var reqDateValue = reqDate.getNumericValue();

//get current date/time in MS
var dateobj = new Date();
var dateObject = new Date(dateobj.getTime() + (dateobj.getTimezoneOffset() * 60000));
var currentDateMS = (dateobj.getTime() + (dateobj.getTimezoneOffset() * 60000));


//calculate difference in seconds and add 1209600000 for 13 days after
answer = (((reqDateValue - currentDateMS)/1000) + 1123200000);

 

I have pasted a screen print of the same code below as I find it easier to read:

 

find_real_file.png

 

Thank you for any help in advance.