Write Script to Calculate Time to Resolve/Closed - MTTR (Task Table)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 05:59 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 06:24 AM
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
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 06:42 AM
Hi Abhijit,
Yes i am trying to create one report for both and use task type breakdown on Inc and Task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 06:44 AM
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
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 07:52 AM