Metric Definitions

Nate23
Mega Guru

Hello All,

I want to edit the oob Assigned to duration metric definition on the incident table to end the duration if the ticket is resolved,closed or cancelled. I am not too familiar with this module. I have tried adding different scripts to make this happen and no progress. Any help or direction is appreciated.

Thanks,

Nate

Scripts I have tried are :

change this around from the wiki

if(current.state == 6 || current.state == 17){

  answer = false;

  mi.endDuration();

  gs.log("Closing field durations");

  closeDurations(mi.current);

}

function closeDurations(current) {

      var gr = new GlideRecord('metric_instance');

      gr.addQuery('id', current.sys_id);

      gr.addQuery('calculation_complete', false);

      gr.addQuery('definition.type', 'field_value_duration');

      gr.query();

      while (gr.next()) {

            gs.log("closing: " + gr.definition.name + " for: " + current.number);

            var definition = new GlideRecord('metric_definition');

            definition.get(gr.definition);

            var mi = new MetricInstance(definition, current);

            mi.endDuration();

      }

}

also tried to simplify it down to:

if(current.state == 17){

  mi.endDuration();

}

1 ACCEPTED SOLUTION

It should work when you close or cancel an incident because OOB there is a metric "Open" on incident active field that stops metric when incident closes. So, your closed and cancelled states are handled by that.



For doing on resolved state, you will have to create a metric on state field to end duration.


View solution in original post

8 REPLIES 8

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

HI Nathan,



Is the choice value i.e 17 for the state in above screenshot correct?


It is the choice value for one of the states I was testing.


SME
Giga Guru

I think your first script should work...There is another OOB metric running "Create to Resolve Duration". are you sure the metric you see still running is the one you are ending?


So I created an incident assigned it to my self is shows up in the 'Assigned to Duration' but the thing is if that ticket is ever resolved,closed or cancelled it never sets an end duration for that record. so my name will sit there for years with no end duration.