Write Script to Calculate Time to Resolve/Closed - MTTR (Task Table)

Eddie5
Tera Contributor

Hi All,

I am trying to create a report on task table (Inc & SC Task only) for MTTR. We need to calculate time duration from opened to resolved for Incident and Opened to Closed for Sc_Tasks.
Can we write a script on task table to compare these two values and get summed duration on indicators for MTTR metric?

I am aware we have OOO reports on incident table and we have customized it for sc_task table however this time we want this on task table (task) so need help how to script this?

Below is script used OOO

var diff=function(x,y){return y.dateNumericValue() - x.dateNumericValue();};
var hours=function(x,y){return diff(x,y)/(60*60*1000);};
hours(current.opened_at, current.closed_at);

We have reached till here and unable to modify script to get comapre values to get duration. 

 

find_real_file.png

11 REPLIES 11

Abhijit4
Mega Sage

Hi,

So are you trying to have only one report on task table which should work for both Incident and sc_task table?

Thanks and Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Eddie5
Tera Contributor

Hi Abhijit,

Yes i am trying to create one report for both and use task type breakdown on Inc and Task

then you can try something like below,

var diff=function(x,y){return y.dateNumericValue() - x.dateNumericValue();};
var hours=function(x,y){return diff(x,y)/(60*60*1000);};
if(current.sys_class_name=='sc_task')
 hours(current.opened_at, current.closed_at);
else if(current.sys_class_name=='incident')
hours(current.opened_at, current.resolved_at);

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Eddie5
Tera Contributor

Hi Abhijeet,

Can you please help field to be selected on task table for resolved field?

find_real_file.png