- 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 09:37 AM
HI Nathan,
Is the choice value i.e 17 for the state in above screenshot correct?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2015 09:51 AM
It is the choice value for one of the states I was testing.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2015 09:46 AM
I think your first script should work...There is another OOB metric running "Create to Resolve Duration". are you sure the metric you see still running is the one you are ending?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2015 09:55 AM
So I created an incident assigned it to my self is shows up in the 'Assigned to Duration' but the thing is if that ticket is ever resolved,closed or cancelled it never sets an end duration for that record. so my name will sit there for years with no end duration.