Welcome Login
Blog Photos Links

RSS Feed

ServiceNow Workflow Timer Script - X days before/after date

December 14, 2012, 2:03 pm - James Farrer

This has come up a couple of times in the last couple days so I thought I'd post it here for future reference.

When you have a date variable in a catalog item and you need to assign a task or do something X number of days before or after the date then you can use this script in a workflow Timer activity. I made some adjustments to make it easier to put in the number of days. Be sure to replace var_name with the name of the date variable you're using.

// Number of days to wait after the date in var_name (for days before the date, use negative numbers
var number_of_days = 1;

// Calculate x number of days after the due date and convert to seconds
var time = (parseInt(gs.dateDiff(gs.nowDateTime(), current.variable_pool.var_name.getDisplayValue(), true), 10) + (number_of_days * 86400));
// Set 'answer' to the number of seconds this timer should wait
answer = time;

Morgan G

Did something change when pasted? My SN throws "Missing radix parameter" with the above.

James Farrer

There is an optional second parameter for the parseInt function that, depending on the version of your SN syntax editor, can cause a warning. Since the parameter is optional it shouldn't affect the result of the code. I have updated the code to include the second parameter. Thanks.

A.K

This was really helpful ! Thanks !! :)


What's New

There are currently no new items, please check back later.

Archives
2021 (2)
  September (1)
  May (1)
2019 (1)
  August (1)
2018 (3)
  August (1)
  April (1)
  January (1)
2017 (1)
  January (1)
2016 (4)
  December (1)
  November (1)
  May (1)
  January (1)
2015 (1)
  December (1)
2014 (2)
  August (1)
  February (1)
2013 (4)
  October (1)
  July (1)
  June (1)
  April (1)
2012 (11)
  December (2)
  October (3)
  September (1)
  May (1)
  April (1)
  February (2)
  January (1)
2011 (14)
  December (1)
  November (1)
  September (2)
  July (2)
  June (1)
  May (1)
  April (2)
  March (3)
  January (1)
2009 (2)
  October (1)
  June (1)
2008 (1)
  September (1)