Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Metric to measure time incident is assigned to person to time it is resolved

SandyL83
Tera Guru

Hello,

I am trying to create a metric to  measure the time from when an incident is assigned to a person (incident state changes to "Assigned") and the time the incident is Resolved (incident state changes to Resolved). 

I have the following code, but it seems to me measuring from open to resolve, not assigned to resolved. 

(Resolved= -3, Assigned is -3). Any ideas?

 

    var s = current.state;
    var mi = new MetricInstance(definition, current);
    if (mi.metricExists()) {
      if (s == 6) {
          mi.endDuration();
      }
    } else if (s == -3) {
        mi.startDuration();
    }
1 ACCEPTED SOLUTION

Ranjit Nimbalka
Mega Sage

Hi @SandyL83 ,

 

You can refer this https: //www.servicenow.com/community/itsm-forum/incident-metric-calculate-time-between-first-assigned-to-unt...

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

 

Regards,

Ranjit

 

View solution in original post

6 REPLIES 6

Ranjit Nimbalka
Mega Sage

Hi @SandyL83 ,

 

You can refer this https: //www.servicenow.com/community/itsm-forum/incident-metric-calculate-time-between-first-assigned-to-unt...

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

 

Regards,

Ranjit

 

Bert_c1
Kilo Patron

Hi SandyL83,

 

I suggest you look at the OOB metric defined for the 'incident' table and the 'incident_state' field named "Create to Resolve Duration". I do not have a choice value for 'incident_state' that is "Assigned".  The script for that metric definition is:

 

// variables available
// current: GlideRecord -  target incident
// definition: GlideRecord -  (this row)
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();
}

You can see the start value here is the 'created_on' field, so I suspect you need a "assigned_on" field to use a metric.  Others here may have another suggestion.

Bert_c1
Kilo Patron

And I see that is confirmed in the Accepted answer to the post Ranjit posted. You'll need a business rule to set the custom field that stores when the incident is assigned.

Hello, thank you! 

I created a custom field to capture when the incident is assigned (u_time_assigned). 

then, I set up this Before, Insert Business Rule.

 

However, it's still not setting that field. Any ideas on what I have wrong?

 

(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_time_assigned = date_assigned_to;
    }  

})(current, previous);