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

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.


Hi ,

 

Would you be able to answer a similar Metric related question?

https://community.servicenow.com/community?id=community_question&sys_id=92bd9c38db5b18903daa1ea66896191d

Michael Fry1
Kilo Patron

The oob Assigned to duration metric is a 'field value' duration on the Assigned to field. You would be better off to create a new 'Script Calculation' metric on the State field. Then your script should work assuming if you have correct values for state.


I want to Track the assigned to field like this metric is doing. just I want it to throw an end duration when the state is resolved,closed or cancelled