- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2015 09:35 AM
Hello All,
I want to edit the oob Assigned to duration metric definition on the incident table to end the duration if the ticket is resolved,closed or cancelled. I am not too familiar with this module. I have tried adding different scripts to make this happen and no progress. Any help or direction is appreciated.
Thanks,
Nate
Scripts I have tried are :
change this around from the wiki
if(current.state == 6 || current.state == 17){
answer = false;
mi.endDuration();
gs.log("Closing field durations");
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()) {
gs.log("closing: " + gr.definition.name + " for: " + current.number);
var definition = new GlideRecord('metric_definition');
definition.get(gr.definition);
var mi = new MetricInstance(definition, current);
mi.endDuration();
}
}
also tried to simplify it down to:
if(current.state == 17){
mi.endDuration();
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2015 10:02 AM
It should work when you close or cancel an incident because OOB there is a metric "Open" on incident active field that stops metric when incident closes. So, your closed and cancelled states are handled by that.
For doing on resolved state, you will have to create a metric on state field to end duration.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2015 10:02 AM
It should work when you close or cancel an incident because OOB there is a metric "Open" on incident active field that stops metric when incident closes. So, your closed and cancelled states are handled by that.
For doing on resolved state, you will have to create a metric on state field to end duration.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2020 10:10 AM
Hi ,
Would you be able to answer a similar Metric related question?
https://community.servicenow.com/community?id=community_question&sys_id=92bd9c38db5b18903daa1ea66896191d

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2015 09:50 AM
The oob Assigned to duration metric is a 'field value' duration on the Assigned to field. You would be better off to create a new 'Script Calculation' metric on the State field. Then your script should work assuming if you have correct values for state.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2015 09:58 AM
I want to Track the assigned to field like this metric is doing. just I want it to throw an end duration when the state is resolved,closed or cancelled