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

Average Resolution Time Based on Business Hours

KirstinR
Mega Expert

I would like to calculate the "Average Resolution Time" based on our business hours.    

I have created:

2 Automated Indicators:

        1) Summed Duration of Closed HR Cases

        2) Number of Closed HR Cases
1 Formula Indicator:   ([[Summed duration of closed HR Cases]] / [[Number of closed HR Cases]]

I am not very familiar with script so I have found the following script in the SN community which I am using in the Summed Duration automated indicator.   How would I incorporate a specific schedule into the script?

var diff=function(x,y){return y.dateNumericValue() - x.dateNumericValue();};

var days=function(x,y){return diff(x,y)/(24*60*60*1000);};

days(current.sys_created_on, current.sys_updated_on);

Thank you in advance for your help.

8 REPLIES 8

KirstinR
Mega Expert

All the advise is very helpful.



Would anyone know how to incorporate the GlideSchedule into the following script?



var diff=function(x,y){return y.dateNumericValue() - x.dateNumericValue();};


var hours=function(x,y){return diff(x,y)/(60*60*1000);};


hours(current.u_open, current.u_resolved);


Padmanabam Tiru
ServiceNow Employee
ServiceNow Employee

Hi Kirstin,



use the below code snippet for using glideschedule to calculate business duartion. Replace the hardcoded schedule sysid with the schedule sysid as you want. This will return the business hours difference between the two dates.



var businessDuration = function(open,resolved){


var startDate = new GlideDateTime(open);


var endDate = new GlideDateTime(resolved);


var schedule = new GlideSchedule();



schedule.load('08fcd0830a0a0b2600079f56b1adb9ae'); // loads "9-5 weekdays" schedule


var duration = schedule.duration(startDate, endDate);


gs.info(duration.getDurationValue()); // gets the elapsed time in schedule


duration = (duration.getNumericValue() / (1000 * 60 * 60))


gs.info(duration);


return duration;


};


businessDuration(current.u_open,current.u_resolved);


This hardcodes in the schedule to use.   Depending on your needs, you may want to pass in the schedule to use to determine what the business hours are.   For instance, you may pass in current.caller.schedule or current.assigned_to.schedule.   If you use the same default schedule (9-5 in this case), you may want to pass in the timezone to GlideSchedule since the start of the day in San Jose very different to that in London.


Padmanabam,   Thank you so much.   This worked!