The CreatorCon Call for Content is officially open! Get started here.

Metrics not calculation in OnHold State

Baker1
Tera Guru

The OnHold Reason Duration creating a new record every time when we change state (OnHold- In Progress- OnHold- In Progress - ViceVersa) every time. It should be should be aggregating time, When It goes to OnHold State.

 

Requirement

Need help creating Metrics Defination for incident


calculates duration that the incident spent in On Hold Awaiting Caller status (increment the duration if the incident was in on hold awaiting caller then went to in progress and went back to awaiting caller, etc.)

 

var rd = new MetricInstance(definition, current);
var state = current.state;
var stateOfOnhold = current.hold_reason;
if (stateOfOnhold == '1') {
createMetrics();
}
if ((stateOfOnhold != '1') && (rd.metricExists())) {
updateEndTimeMetrics();
}

function createMetrics() {
var rr = rd.getNewRecord();
rr.start = current.sys_updated_on;
rr.calculation_complete = false;
rr.value = current.getDisplayValue('state');
rr.insert();
return;
}

function updateEndTimeMetrics() {
var gr = new GlideRecord('metric_instance');
gr.addQuery('id', current.sys_id);
gr.addQuery('definition', 'ad9237402743094848333e40');
gr.orderByDesc('sys_created_on');
gr.query();
if (gr.next()) {
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start, gr.end);
gr.calculation_complete = true;
gr.value = current.getDisplayValue('state');
gr.update();
}
return;
}

1 ACCEPTED SOLUTION

Hi @nowgpt1 
Thank you for quick reply

I need to add If condition in it. Could you please help me.

The OnHold Reason Duration creating a new record every time when we change state (OnHold- In Progress- OnHold- In Progress - ViceVersa) every time. It should be aggregating time, When It goes to OnHold State.

View solution in original post

2 REPLIES 2

Hi @nowgpt1 
Thank you for quick reply

I need to add If condition in it. Could you please help me.

The OnHold Reason Duration creating a new record every time when we change state (OnHold- In Progress- OnHold- In Progress - ViceVersa) every time. It should be aggregating time, When It goes to OnHold State.

Baker1
Tera Guru

Hi @nowgpt1 

Anyupdate please