Workflow timer script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2017 09:00 AM
Hi all I hope you can help me resolving this issue.
I have a
workflow that is supposed to trigger a timer for 30,60,90 etc for selected end
date a user enters. Example if user enters 01/12/2017 and select to be notified
30 days before the end date. I need the workflow to pause until 12/12/2017.
Below is the
script I am using however I don't think it's working
var start = new GlideDateTime(current.ends);
var old_end_date = start.getDate();
old_end_date.addDays(-30);
var NewEnd = new GlideDateTime(old_end_date);
// Duration in days
var dur = new GlideDuration();
var dur = GlideDateTime.subtract(NewEnd,start); //the
difference between gdt1 and gdt2
// Duration in
hours
var dur_seconds = gs.dateDiff(NewEnd,start, true); //
returns the number of seconds as String
var dur_hours = Math.round(dur_seconds / 3600); //
Math.round() is optional and will round the number to the nearest integer
answer=dur_seconds;
any suggestion would be appreciated
Thank you
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2017 01:39 PM
I am looking at your first line:
var start = new GlideDateTime(current.ends);
Not sure what current.ends is supposed to point to.
Is this a variable? If it is, then add variables to your assignment:
var start = new GlideDateTime(current.variables.ends);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2017 09:08 AM
Hi Chirstopher Thank you for responding and I hope you can help me
current.ends refers to the current record field called "ends" which is a date field. What I am trying to do I am trying to retrieve the data submitted in this field called date a do a 30 day calculation
Please advise

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2017 09:30 AM
If the field is a date field, then you may not even need to script it. You should be able to change the "Timer based on" field to be: A date/time or duration field, then select the field you mentioned. Below the field selection menu, is another menu where you can define how you will be waiting. Most likely you will choose "Sometime before" then define how long.
For more information on what other options you have for the TImer workflow activity, please see ServiceNow documentation:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2017 09:18 AM
Thank you again for responding. So are you saying that if I want the workflow to run 30 days before the end date then I should set it to run on the 31st day
Please advise
Thank you again