Average resolution time to resolve a ticket

velvet
Mega Guru

I have a question about the Average Resolution time for Incident scorecard:  We use the scorecard a lot for this indicator, but we also have a widget on the portal with the monthly average resolution time for incidents.  The issue is, I know that the scorecard uses the created date to the resolution date, which is accurate.  But the script that was written for me on the portal, I think it was written to only calculate the incidents that were Created and Resolved in the last 30 days.  I am new to scripting so can someone tell me that the script below is using only the incident that were created and resolved in the last 30 days.

var MWHCPortalStats = Class.create();
MWHCPortalStats.prototype = {
initialize: function() {
},
averageIncidentResolveTime: function(){
var avg = getAverage();

function getAverage() {
var rec = new GlideRecord('metric_instance');
rec.addEncodedQuery('definition=35edf981c0a808ae009895af7c843ace^sys_created_onONLast 30 days@javascript:gs.daysAgoStart(30)@javascript:gs.daysAgoEnd(0)');
rec.query();
var time = 0;
var count = rec.getRowCount();
while (rec.next()) {

var dur = rec.duration.getDurationValue().toString();
// Check for days, if so convert the days to seconds
if (dur.split(' ').length > 1) {
dur = dur.split(' ');
// get days
if(dur[0])
time += (parseInt(dur[0], 10) * 86400);
dur = dur[1];
}
// Split to hours/minutes/seconds
dur = dur.split(':');

// Add hours
if(dur[0])
time += (parseInt(dur[0], 10) * 3600);

// Add minutes
if(dur[1])
time += (parseInt(dur[1], 10) * 60);

// Add seconds
if(dur[2])
time += parseInt(dur[2], 10);
}
return Math.floor(time / count);
}
return {
avg: Math.ceil(avg/60/60),
unit: "HRS"
};
},
customerSatisfaction: function(){
var incs = new GlideRecord('survey_response');
incs.addEncodedQuery('question=c32c23c9dbf58380c7e57afc0f9619e9');
incs.query();
var total = parseInt(incs.getRowCount());
var score = 0;
if(!incs.hasNext()){
return {
avg: 10
};
}
while(incs.next()){
score += parseInt(incs.response);
}
return {
avg: ((score/(total*3))*10) == 10 ? parseInt((score/(total*3))*10) : ((score/(total*3))*10).toFixed(1)
};
},

incidentsToday: function(){
var incs = new GlideRecord('incident');
incs.addActiveQuery();
incs.query();
return {
avg: parseInt(incs.getRowCount())
};
},
type: 'MWHCPortalStats'
};

1 ACCEPTED SOLUTION

Johnnie O_
Kilo Guru

This line:

var rec = new GlideRecord('metric_instance');
rec.addEncodedQuery('definition=35edf981c0a808ae009895af7c843ace^sys_created_onONLast 30 days@javascript:gs.daysAgoStart(30)@javascript:gs.daysAgoEnd(0)');

Is querying the 'Create to Resolve Duration' metrics from the metric instance table created in the last 30 days.

 

So basically, yes, it appears to be looking at only incidents resolved in the last 30 days.

View solution in original post

2 REPLIES 2

Johnnie O_
Kilo Guru

This line:

var rec = new GlideRecord('metric_instance');
rec.addEncodedQuery('definition=35edf981c0a808ae009895af7c843ace^sys_created_onONLast 30 days@javascript:gs.daysAgoStart(30)@javascript:gs.daysAgoEnd(0)');

Is querying the 'Create to Resolve Duration' metrics from the metric instance table created in the last 30 days.

 

So basically, yes, it appears to be looking at only incidents resolved in the last 30 days.

Just to clarify, it is looking for the metric to be created in the last 30 days, which only happens when the incident is resolved. So not looking for incidents created in the last 30 days, but incidents resolved in the last 30 days.