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

ccajohnson
Kilo Sage

Perhaps if you let us know what you are trying to achieve, we can assist in guiding you.

Please keep in mind that all time fields in service now use GMT as the time when it is stored. Time Zones allow a user to see that time in their local time if their user record is set for that Time Zone.

Ksnow
Tera Contributor

I have a requirement, I will try to put in a simple way to understand.

It's related to SLA subject and it's custom implementation. Time zones and schedules are involved in this subject. I want to calculate the Acknowledge duration, usually calculation is from incident opened_at to incident is assigned to someone(assigned to field filled).

I have defined time zone and schedule in the each business service that will be reflected in the incident form, based on this time zone and schedule acknowledge duration should be calculated.

Here is the example:

If the incident is opened at 5.45 AM in the Asia/Kolkata time zone. The defined schedule is 9am-6pm with time zone Asia/Kolkata

The supporter(Asia/Kolkata time zone user) who is going to work on the incident assigned the incident to himself at 8 AM in the morning, Acknowledge duration should be zero/null because it should consider from 9am-6pm within the Asia/Kolkata time zone.

I am using the below script to get the job done.

var gdt = new GlideDateTime(current.getDisplayValue("opened_at")); //opened_at time

var nowUTC = new GlideDateTime(gs.nowDateTime()); // 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;

 

I tested the above script multiple times, I found that the calculation is being done from 8am-5pm instead of 9am-6pm in Asia/Kolkata time zone. It's calculating one hour early.

NOTE: My system property time zone is Europe/Zurich(UTC+1)

How to make the calculation correctly as per the schedule and the time zone as defined in the business service?

Please help me out. Appreciate your response.

Thanks.

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;

Ksnow
Tera Contributor

Thank you so much for your help ccajohnson.

I tried like you suggested, It's working fine now.

I would like to ask you another question which is related to response duration calculation, It supposed to be calculated from the incident opened at to till the incident closed and it should exclude the on hold, solution proposed and awaiting parent info time from the overall time(Opened at - Closed). When I try to implement as you suggested the value is still showing zero"0".

Here is the script:

var gdt = new GlideDateTime(current.getValue("opened_at")); // opened at time
var nowUTC = new GlideDateTime(); // current time
var dur = new GlideDuration();
var timeZone = current.u_time_zone_bs; // timeZone in incident
var schedule = current.u_sla_schedules; // schedule in incident
var sched = new GlideSchedule(schedule , timeZone); // schedule declaration with incident schedule and timezone

dur=sched.duration(gdt,nowUTC);
var gr = new GlideRecord("metric_instance");
gr.addQuery("id", current.sys_id );
gr.addEncodedQuery("value=Awaiting parent information^ORvalue=Solution Proposed^ORvalue=on hold");

gr.query();
while (gr.next()) {
var value = new GlideDateTime(gr.duration); // time of all 3 states,how long it is on each state for current incident

dur=sched.duration(value,dur); // difference between opened time and assigned_to filled time


}
current.u_response_duration = dur;

 

How can I get this job done within the schedule and time zone by excluding the on hold, solution proposed and awaiting parent information times?

Please advise, appreciate your time and patience.

Thank you,

Ksnow