Complete metric instances after ticket is closed

Annika Aaltonen
Kilo Guru

There are some OOTB metrics definitions on the incident table, out of which the ones tracking Assignment group and Assigned to Duration are completing / closing once the ticket changes to inactive, and the duration is calculated.

I created these same metrics on the sc_req_item table, but this above described behaviour is not happening. When I close the RITM ticket, the metric instances tracking the current values of assignment group and assigned to are left active with no duration. What do I need to change to reflect this same behaviour that is occurring OOTB on the INC table?

TIA,

Annika

1 ACCEPTED SOLUTION

Annika Aaltonen
Kilo Guru

Solution:

I needed to create a new Metric Definition on the sc_req_item table (same definition exists on the INC table OOTB, so just copy that one, called "Open") on the Active field, with a script to take care of completing the duration calculations:

 

if (!current.active) {
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.query();
while (gr.next()) {
var definition = new GlideRecord('metric_definition');
definition.get(gr.definition);
var mi = new MetricInstance(definition, current);
mi.endDuration();
}
}

View solution in original post

5 REPLIES 5

Hi Linda,

This was indeed something I had to figure out next, after solving the issue posted here.

 

Please check my post:

https://community.servicenow.com/community?id=community_question&sys_id=88db0d42db6e4950e2adc223059619c1

 

You might have to adjust the script for your own requirements, but this script basically completed the still active metrics retroactively and populated all the missing fields, only for the two metric definitions mentioned here though.

 

Best,

Annika