Workflow Timer Script Example

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2011 02:26 PM
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);
- 6,113 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2011 09:15 AM
Hi Eric,
Thank you for taking the time to share!
-Lawrence
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2014 03:17 PM
Eric,
Thanks for posting this information - I was able to use it as a starting guide for something similar that I am trying to do with a workflow timer being set from a variable that is set in a catalog task before the timer. For this example I wanted the timer to wait until the day after the variable "install_date" was set to in the catalog task.
//get "install_date" variable from the request item
var installDate = new GlideDateTime();
installDate.setDisplayValue(current.variables.install_date.getDisplayValue());
//convert install_date value to millisecond value
var installDateValue = installDate.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 86400 for the day after
answer = (((installDateValue - currentDateMS)/1000) + 86400);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2018 08:25 AM
Thanks
you help me a lot too!
🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2018 08:24 AM
Thanks a lot!
It was very helpful 🙂