script to subtract pause duration from metric definition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 09:00 AM
I have a code which will calculate time from Incident created to resolved.
I want to exclude Pause duration from that Metric definition.
If the Incident is in Awaiting state, that duration needs to be removed.
Please help me on this, as I am not able to figure out
var s = current.incident_state;
if (s >= 6)
createMetric();
function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;
var gr = mi.getNewRecord();
gr.start = current.sys_created_on;
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.calculation_complete = true;
gr.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2023 01:11 PM
Hi, based on your post I am assuming your code works and you are just looking to set or exclude 'duration' based on task state being 'On hold', yet this seems to have been excluded in your initial state check
OOB On-hold == 3 and your metric is only created if state >= 6?
Have you tried excluding population of the duration field?
if(current.incident_state == someInteger){
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 07:03 AM
Thanks for responding.
How can I exclude the awaiting state. For suppose in my instance awaiting value is 4, how to exclude the state.
Can you please help me with the code.
