- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2017 01:43 AM
I have created a metric which store duration how much time a assignment group is taking. but this metic should end when ticket is closed
calculation should complete and metric should provide duration when ticket is closed or inactive
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 08:50 PM
Hi Alikutty,
below is the code which i found from communities which is running for me,
if (current.state == 6) { //change according to your closed state
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'); //mark your metric definition sysid
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
‎08-23-2020 01:04 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2020 04:18 AM
Thank you
I am having same script as yours, but its not closing when case is closed. Only difference is, my metric is running on Assignment group field value & yours is on Active. Do I need to change anything in the above script to accommodate the difference. Appreciate your advice!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2020 12:25 PM
Hi
The intention of the 'active' metric is that it closes off all the other metrics against the records. Without this metric, on the active field, when the Case is closed the other metrics will not also close off properly.
You will need t either update your metric to use the 'active' field, or if you need to continue to measure your 'assignment group' metric, create a new metric that is on the 'Active' field.
My HR Metric weren't closing off properly either until I created the HR metric on 'Active'.
Hope this helps.
Cheers
Carl.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2020 12:35 PM
Ok, so I need to create two metrics - as I want to measure total time Assigned to has the case - one for Assigned to & one for Active.
But then How can I combine these two to create one report?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2020 01:36 PM
Hi vikrami,
The Metric on 'Active' is only there for closing off the other metrics - you wouldn't need to combine this with your other metric on Assignment Group. The Assignment Group will be able to provide you the report you need by itself, it 's just that having the 'Active' one actually stops ad closes metric correctly when the ticket is closed. So there's no need to combine these to make one report.
Additionally have you thought about the time measurement for these reports - do you want Business Time, or Total time? By default the metrics all use Total Time, so a 24x7 clock vs using a Business Time clock which could be 8am to 5pm only. Something additional to think about once you get the above working.