Metric on Assignment Group when Incident is Resolved

razvan1
Giga Contributor

Hello,

I'm trying to change the metric on Assignment Group so it will stop when the incident state will be Resolved (in this moment it stops when the incident state is Closed / not active anymore). The only info regarding this I found on this wiki page : Metric Definition Support - ServiceNow Wiki but the example script does not help me.

How this script should be implemeted (on a new metric, on a bussines rule,   to add it on the existing Assgiment group Metric...) ? Did someone already this change?

Thank you in advance!

3 REPLIES 3

Harish Murikina
Tera Guru

The OOb script stopping metric when ever active is false . If you want to stop when ever state changes to resolved modify the if condition



if (current.state == '6') {


  answer = false;


  mi.endDuration();


  gs.log("Closing field durations");


  closeDurations(mi.current);


}


razvan1
Giga Contributor

I found another discussion on the community forum and I manged to solve this. Thank you also Harish for you answer.


Here is the complete solution from Assignment group metric calculation in Incident :



"Discovered that the "Open" metric in incident table was the one ending the calculation of the Assignment group metric, when the active flag turned false (state moving to Closed).



Instead of letting this "Open" metric end the calculation, we created another metric to end it when state moves to Resolved (Special case that closes out (ends) assignment group metrics when state changes to Resolved): "



============================================================


Table: Incident


Type: Field Value Duration


Field: State



Script:


if (current.state == 6) {


  answer = false;


  mi.endDuration();


  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.addQuery('definition', '39d43745c0a808ae0062603b77018b90');


  gr.query();


  while (gr.next()) {


  var definition = new GlideRecord('metric_definition');


  definition.get(gr.definition);


  var mi = new MetricInstance(definition, current);


  mi.endDuration();


  }


}


==========================================================



razvan1
Giga Contributor

From the wiki page example, this line is missing: gr.addQuery('definition', '39d43745c0a808ae0062603b77018b90');