add duration to date time given a schedule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 06:30 AM
There is a requirement to add some 2 days duration to a date time based on the schedule. Please let me know how this can be achieved.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 07:08 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 07:19 AM
Here you go.
var startDate = new GlideDateTime('2014-01-02'); //your start date goes here
var days = 2;
var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828'); //pass the sys_id of your schedule and second parameter can be time zone which is optional
var end = schedule.add(startDate, dur);
gs.info(end);
Scoped GlideSchedule API Reference - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 08:15 AM
Tried a similar script
var st = gs.nowDateTime();
var days = 2;
var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);
var schedule123 = new GlideSchedule('sys_id of schedule');
var end = schedule123.add(st, dur);
gs.print(end);
This works fine in my developer instance but the same does not work in my original instance and it gave me following error when tried executing as a background job
Can't find method com.glide.schedules.Schedule.add(string,com.glide.glideobject.GlideDuration). (null.null; line 9)
Please let me know the difference as same script is made to run on both the instances.
Wiki article says these functions will be available from fuji.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 08:36 AM
Well It worked for me. These are available on Fuji as well