- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2022 06:57 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2022 06:02 AM
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();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2022 07:29 AM
why dont you share all ur code and config ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 03:39 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2022 06:02 AM
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 05:58 PM
Do you know how to update the metrics for tickets that were already closed? I'm not sure if a fix script would work?