How Glide schedule works with the time zone?

Ksnow
Tera Contributor

Hello All,

I would like to ask you all how glide schedule works with the time zone?

Will it consider system properties time zone? even after providing separate time zone in the incident with the schedule.

NOTE: Please don't provide links, I am not able to get the information what I'm looking for.

Can anyone let me know how it works? I am working on this from many days, it's making me crazy.

Appreciate your response, thank you in advance.

Regards,

Ksnow

1 ACCEPTED SOLUTION

ccajohnson
Kilo Sage

My guess is that this is a Business rule that sets the Acknowledge duration field when the Assigned to field is first populated. Since this is a business rule, we do not have to get the display value of the fields nor do we need to get the local time of the user when generating Now.

Most likely since you are testing in a different time zone than the example, the times would be off. I took your script and used the times you indicated as if they were stored in GMT and ran it in Scripts - Background. Since I do not have your schedule for 9am-6pm, I used the OOB schedule for 8-5 weekdays. I also set the Time Zone to be GMT so that we are clear what the manually entered times will be against the schedule. Here is what I have:

var gdt = new GlideDateTime('2020-01-21 05:45:00');
var nowUTC = new GlideDateTime('2020-01-21 08:00:00');
var timeZone = 'GMT';
var dur = new GlideDuration();
var schedule = '08fcd0830a0a0b2600079f56b1adb9ae';
var sched = new GlideSchedule(schedule, timeZone);
dur =sched.duration(gdt,nowUTC);

gs.info(dur);

I find that if the nowUTC value is before the start time of the schedule the duration is 0. Anything after the start date shows the duration within the schedule. Feel free to adjust the nowUTC time to see what I mean.

I would remove any getDisplay type functions from your code so that we will only set the Time Zone of the schedule to calculate from the stored value rather than the display value:

var gdt = new GlideDateTime(current.getValue("opened_at")); //opened_at time
var nowUTC = new GlideDateTime(); // current time(assigned to field filled)
var timeZone = current.u_time_zone_bs; // defined time zone in the incident form which is populating from Business service. Time zone here is Asia/Kolkata
var dur = new GlideDuration();
var schedule = current.u_sla_schedules; // defined Schedule in the incident form which is populating from Business service. Schedule here is 9am-6pm
var sched = new GlideSchedule(schedule , timeZone);
dur =sched.duration(gdt,nowUTC);
current.u_acknowledge_duration=dur;

View solution in original post

7 REPLIES 7

Ksnow
Tera Contributor

Any leads @ccajohnson 

Please suggest

var start_date = new GlideDateTime();
var end_date= new GlideDateTime();
start_date.setDisplayValue("2023-03-29 08:00:00");
end_date.setDisplayValue("2023-04-10 09:00:00");
var eigh_x_five='08fcd0830a0a0b2600079f56b1adb9ae';
var schedule=new GlideSchedule(eigh_x_five);
var schedule_duration=schedule.duration(end_date,start_date);
gs.info('schedule: '+schedule.getName())
gs.info(schedule_duration);
 
I am getting this output, which is incorrect and my time zone is GMT
*** Script: schedule: 8-5 weekdays
*** Script: 1970-01-01 00:00:00
 

Please start a new thread, this has thread has been solved. For you example try:

 

var start_date = new GlideDateTime();
var end_date= new GlideDateTime();
start_date.setDisplayValue("2023-03-29 08:00:00");
end_date.setDisplayValue("2023-04-10 09:00:00");
gs.info("start_date = " + start_date + ", end_date = " + end_date);


var dur = new DurationCalculator();

// Set 8-5 weekday schedule. This is the schedule in which endDateTime, seconds, and totalseconds is set
dur.setSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); 
dur.calcScheduleDuration(start_date, end_date);
var secs = dur.getSeconds();
var totalSecs = dur.getTotalSeconds();

gs.info("***SCHEDULE DURATION: SECS=" + secs + " TOTALSECS=" + totalSecs + " ENDTIME = " + end_date);


dateObj = new Date(null);
dateObj.setTime(secs * 1000);

gs.info("dateObj = " + dateObj);

which gives:

*** Script: start_date = 2023-03-29 12:00:00, end_date = 2023-04-10 13:00:00
*** Script: ***SCHEDULE DURATION: SECS=262800 TOTALSECS=1040400 ENDTIME = 2023-04-10 13:00:00
*** Script: dateObj = Sat Jan 03 1970 17:00:00 GMT-0800 (PST

and convert 'secs' as desired.

 

https://developer.servicenow.com/dev.do#!/reference/api/utah/server_legacy/c_DurationCalculatorAPI#r...