script to subtract pause duration from metric definition

Chaitanya Mumma
Tera Contributor

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();
}

2 REPLIES 2

Tony Chatfield1
Kilo Patron

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());
}

 

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.