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

Ravi9
ServiceNow Employee
ServiceNow Employee

why dont you share all ur code and config ? 

Hi Ravi,

 

The only thing I did so far is I inserted new Metric definitions for Field Value Duration on the fields Assigned to, Assignment group and State on the sc_req_item table. There is no code etc.

Everything seems to be working fine except this issue I described above. So I wonder if I need to reflect these new Metric definitions in some existing BRs, Script Includes or similar for them to work the same way as the ootb ones.

 

Thanks!

Annika

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();
}
}

Do you know how to update the metrics for tickets that were already closed? I'm not sure if a fix script would work?