Incident Metric - Calculate time between first assigned to until resolution.

Manan4
Kilo Contributor

One of our clients needs to have a report created that would show them the time taken to complete an INC after it was assigned to an ITIL User. Their SLA Definitions for resolution calculate the entire lifecycle of the INC from the time it was opened until closed. I came across the Metrics table and found the below Metric for INC which calculate the duration from Open to Resolved/Closed. 

Hoping to build a similar metric that would allow me to calculate duration from first assigned to until Resolved/Closed. Any help or suggestions would be much appreciated. Thank you.

find_real_file.png

1 ACCEPTED SOLUTION

Hajar BENJAHHAR
Mega Sage

Hello @Manan ,

So what I suggest to you is to create a field type Date/Time to store type when the field changes for the first time : 

find_real_file.png

To get the time when assigned to changes for the first time you have to create a before business rule as shown bellow : 

(function executeRule(current, previous /*null when async*/ ) {
	
    if (gs.nil(previous.assigned_to) && current.assigned_to) {
        var date_assigned_to = new GlideDateTime(gs.nowDateTime());
        current.u_assigned_to_changes_on = date_assigned_to;
    }

})(current, previous);

Results after assign incident to a user : 

find_real_file.png

 

The last step is to create a metric and start calculating : 

// current: GlideRecord -  target incident
/*if (current.assigned_to) {
        createMetricAssignedTo();
}*/
var state = current.state;
if(state>=6){
	createMetric();
}

function createMetric() {
  var mi = new MetricInstance(definition, current);
  if (mi.metricExists()) 
    return; 

  var gr = mi.getNewRecord();
  gr.start = current.u_assigned_to_changes_on;
  gr.end = current.sys_updated_on;
  gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
  gr.calculation_complete = true;
  gr.insert();
}

 Results : 

Closed incident :

find_real_file.png

 

 

find_real_file.png

 I hope that what you are looking for. 

Best regards.

View solution in original post

7 REPLIES 7

Rozmin Parpia
ServiceNow Employee
ServiceNow Employee

The metric definition Create to Resolve - is a good one to model on. The script is below.

The metric uses the created on field to set the Start date: gr.start = current.sys_created_on;

Create a new field, like Work in Progress (doesn't have to be on the form) that captures the data/time when ticket State changes to Work in Progress.

Then copy the script that just change the one line - gr.start = current.newfieldhere;

var s = current.incident_state;
if (s >= 6)
createMetric();

function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;

var gr = mi.getNewRecord();
gr.start = current.sys_created_on;
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.calculation_complete = true;
gr.insert();
}

Hello, in his requirement he has to capture two things : first one is when the ticket is assigned to a user for the first time and the second he has to  track the state of the incident. 

Please see my proposition is more clearly.

Best regards. 

Jackie Frank
Tera Contributor

My use case is slightly different in that I want to create a metric to capture the first time a ticket was Assigned to a person from creation date/time of the ticket. 

I first created a field on Incident to hold the date/time value when the ticket gets first assigned:

 

Then I created the before business rule to populate that field:

Then I created the metric:

I have confirmed that the business rule runs and populates correctly. However, something is wrong with my metric. I don't care what state the ticket is in, I just want to know how much time it took from the ticket being created until the time it first got assigned to a person.

Could someone help me to understand what I am doing wrong? I am extremely new to ServiceNow so any guidance / pointers you can give would be so appreciated.