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

Narendra Kota
Mega Sage

Hi Manish,

Please follow this link and build a report accordingly. It would help you in creating a similar one for your purpose.

MTTR (Mean Time to Resolution) Reporting

Hope this helps.
Mark helpful or correct based on impact.

Thanks.

Hi Narendra,

Thanks for response but i need to calculate this using script and need to populate the value in a separate custom column so creating report will not help.

I  have written the code but not sure why am i not able to get the desired result.

 

Thanks,

Manish

Hi,

Also in addition to Tony's reply, if you are trying to make sum of all the business duration of the incidents, then it's not going to work, if you use it like this way: 

result += gr1.business_duration; // becuase here plus (+) symbol will work like concat 

instead,

please try to add all the duration with some scripts below like this:

var time1 = "01:00:00";
        var time2 = "00:30:00";
        var time3 = "00:30:00";
        
        var hour=0;
        var minute=0;
        var second=0;
        
        var splitTime1= time1.split(':');
        var splitTime2= time2.split(':');
        var splitTime3= time3.split(':');
        
        hour = parseInt(splitTime1[0])+parseInt(splitTime2[0])+parseInt(splitTime3[0]);
        minute = parseInt(splitTime1[1])+parseInt(splitTime2[1])+parseInt(splitTime3[1]);
        hour = hour + minute/60;
        minute = minute%60;
        second = parseInt(splitTime1[2])+parseInt(splitTime2[2])+parseInt(splitTime3[2]);
        minute = minute + second/60;
        second = second%60;
        
        alert('sum of above time= '+hour+':'+minute+':'+second);

Hope this helps.
Mark helpful or correct based on impact.

Thanks.

Thank you Narendra,

Trying to pass the reference value in add query (gr1.addQuery('task','gr.sys_id')) but seems not working.

Please suggest how to pass getReference under addQuery().

Thanks,

Manish