MTTR calculation for resolved/closed ticket

Manish2
Mega Expert

Hello Team,

Hello,

I am looking for calculating the MTTR value for resolved/Closed incident. Let say i have pulled the count of total resolved/closed ticket for a particular group now how to calculate the MTTR value.I don't want to create the MTTR report just need the value , i need to populate this value only.

I have tried to calculate this from task_sla table.

In the below code pulling the incident and passing the incident sys_id in the task_sla table and filtering only resolution SLA. But i am not able to find out why i am not getting the value of business duration.

Please suggest.

var result = 0;
var gr = new GlideRecord('incident');
var querystring3="caller_id=1bcd25cbdb9b1300973056d6dc96191b^sys_created_on>javascript:gs.dateGenerate('2018-12-14','23:59:59')^assignment_group=989e415ddb77fa403eb17e400f9619ba^state=6^ORstate=7";
gr.addEncodedQuery(querystring3);
gr.query();
var count3 =0;
count3=gr.getRowCount();
gs.print("Count"+count3);
while(gr.next())
{
var gr1= new GlideRecord('task_sla');
gr1.addQuery('task','gr.sys_id');
gr1.addEncodedQuery("slaLIKEResolution");
gr1.query();
result += gr1.business_duration;
gs.print("number"+gr.number);
gs.print("Result"+result);
}

Thanks,

Manish

1 ACCEPTED SOLUTION

Thanks Tony for your input.

This code seems to be working fine.

var result=0;
var days = 0;
var second=0;
var mttr=0;
var myDate = gs.nowDateTime();
var gr = new GlideRecord('incident');
var querystring3="caller_id=1bcd25cbdb9b1300973056d6dc96191b^sys_created_on>javascript:gs.dateGenerate('2018-12-14','23:59:59')^assignment_group=989e415ddb77fa403eb17e400f9619ba^state=6^ORstate=7";
gr.addEncodedQuery(querystring3);
gr.query();
var count3 =0;
count3=gr.getRowCount();
gs.print("Count"+count3);
while(gr.next())
{
var gr1= new GlideRecord('task_sla');
gr1.addQuery('task',gr.sys_id);
gr1.addEncodedQuery("slaLIKEEurostar_Resolution");
gr1.query();
while(gr1.next()){
myDate = gr1.business_duration;
var gdt1 = new GlideDateTime(myDate);
var epoch = gdt1.getNumericValue();
result +=epoch;
second=result/1000;
hours=second/3600;
mttr=hours/count3;
gs.print("number"+gr.number);
}
}
gs.print("Result"+result);
gs.print("Second"+second);
gs.print("hours"+hours);
gs.print("MTTR hours"+mttr);

View solution in original post

13 REPLIES 13

Thanks Tony,

 

Getting the output but in epoch format like (1970-01-01 00:03:201970-01-01 00:03:461970-01-01 00:03:171970-01-01 00:02:54), need the business_duration in desires format (14 Days 15 Hours 30 Minutes).

 

Any suggestion to convert this epoch format.

Thanks,

MAnish 

 

Tony Chatfield1
Kilo Patron

Hi, off the top of my head I'm not 100% sure of the code.
You will need to subtract epoch from the returned time stamp and then convert the remainder to a date\time value.

It shouldn't be too difficult and I am sure it has been asked before\the answer is already on the forum somewhere.
You should also take a look at the date\time APIs in case it's already covered.

Thanks Tony for your input.

This code seems to be working fine.

var result=0;
var days = 0;
var second=0;
var mttr=0;
var myDate = gs.nowDateTime();
var gr = new GlideRecord('incident');
var querystring3="caller_id=1bcd25cbdb9b1300973056d6dc96191b^sys_created_on>javascript:gs.dateGenerate('2018-12-14','23:59:59')^assignment_group=989e415ddb77fa403eb17e400f9619ba^state=6^ORstate=7";
gr.addEncodedQuery(querystring3);
gr.query();
var count3 =0;
count3=gr.getRowCount();
gs.print("Count"+count3);
while(gr.next())
{
var gr1= new GlideRecord('task_sla');
gr1.addQuery('task',gr.sys_id);
gr1.addEncodedQuery("slaLIKEEurostar_Resolution");
gr1.query();
while(gr1.next()){
myDate = gr1.business_duration;
var gdt1 = new GlideDateTime(myDate);
var epoch = gdt1.getNumericValue();
result +=epoch;
second=result/1000;
hours=second/3600;
mttr=hours/count3;
gs.print("number"+gr.number);
}
}
gs.print("Result"+result);
gs.print("Second"+second);
gs.print("hours"+hours);
gs.print("MTTR hours"+mttr);

jain25rajesh
Kilo Expert

Use Incident Metric "create to resolved duration" to calculate MTTR as below. You can change conditions as per your need.

find_real_file.png