- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 04:32 AM
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;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 05:04 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 05:04 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 09:05 AM
Hi @nowgpt1
Anyupdate please