The CreatorCon Call for Content is officially open! Get started here.

add duration to date time given a schedule

moulik1
Kilo Guru

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.

4 REPLIES 4

Kalaiarasan Pus
Giga Sage

Abhinay Erra
Giga Sage

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


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.


Abhinay Erra
Giga Sage

Well It worked for me. These are available on Fuji as well