Assigned Ticket Duration

jjarka
Kilo Contributor

I am creating a metric called Assigned Ticket Duration.   The goal is to measure the time it took from the creation of the ticket to the first time it was assigned to a resource, not an assignment group.   I did some digging and found this script from another user that I recreated:

1   if (current.asigned_to != ''){

2   createMetric();

3   }

4

5   function createMetric() {

6   var mi = new MetricInstance(definition, current);

7   if (mi.metricExists())

8   return;

9

10   var gr = mi.getNewRecord();

11   gr.start = current.sys_created_on;

12   gr.end = current.sys_updated_on;

13   gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());

14   gr.calculation_complete = true;

15   gr.insert();

16   }

When I ran the script it appears to return results for many records, but there was one where no results had been returned.   It was a test ticket that I created.   I had opened the ticket at 7:40 am assigned it to the Service Desk Group.   At 7:41 I assigned it to another group I set up and then assigned the ticket to me.   I should have a duration of 1 min.  

I must forewarn you, I have limited scripting expertise so I may have messed up the script. Any help would be greatly appreciated.

1 ACCEPTED SOLUTION

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Line 1. you spelled assigned_to wrong



let me know if you get stuck again


View solution in original post

10 REPLIES 10

So let me recap this to see if I have that correctly.   I created the metric, ran it, it returned results that are incorrect from what I am looking for.   I edit the same metric and rerun it, but it won't update the record to correct the incorrect data?  



If I have that correct what do I need to do to fix this?   Delete the metric and start over?