Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

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

Tony Chatfield1
Kilo Patron
Hi, I think you have gr.sys_id in quotes making it a string and not a reference.

Hi Tony,

Thanks for response.

Not sure how to pass this value as reference in add query (gr1.addQuery('task','gr.sys_id');) as task is using the sys_id of the ticket.

Thanks,

Manish 

Hello Tony,

When i am printing the gr.sys_id then getting the sys_id of the incident not sure why it's not taking in the gr1.addQuery('task',gr.sys_id) as a output of business duration of incident.

gr1.addQuery('task',gr.sys_id);
gs.print("number"+gr.sys_id);

Thanks,

Manish

Hi Manish,

Below link should help you - 

 

https://snipit.io/public/lists/3664/10893

Tony Chatfield1
Kilo Patron

Hi Manish,

gs.print("number"+gr.sys_id); is correct - you are referencing the value gr.sys_id
but the code you posted shows quotes for gr1.addQuery('task','gr.sys_id');


The quotes used make this a string 'gr.sys_id', not a reference
and you need to remove them so that it's a reference IE gr1.addQuery('task', gr.sys_id);