Get Assigned and In Progress duration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2023 12:42 PM
Hi, I'm using Incident_metric table and I need a PA Script to get the Assigned and In Progress duration from "On Hold" tickets. I'm not very familiar with scripts and I believe I need GlideRecord stuff. Can someone help me or tell me how to start?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2023 01:06 PM - edited ‎09-14-2023 01:06 PM
Hello @Sergio Gonzalez,
If you are using a PA Script, first set your fields in the "Fields" label, through this variable you have direct access to those fields, you don't need GlideRecord.
var assigned = current.assigned_to;
var progressDuration = current.in_progress_duration;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2023 10:58 AM - edited ‎09-18-2023 11:02 AM
ok, I was checking the fields for the PA script, but there's no in_progress_duration.
I understand that I have to get the duration from duration field but when values is assigned and in progress, but is it possible just like you did without GlideRecord? Also, How can I check the duration just for On Hold tickets if I'm using Value=On Hold?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2023 01:53 PM
Created this script, but didn't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2023 03:21 PM
Hi Sergio,
Here's and example of a metric I have named "Assigned to Duration - SC Task" defined on the sc_task table. If you want to use that feature, base your script logic like:
// variables available
// current: GlideRecord - target incident
// definition: GlideRecord - (this row)
var s = current.incident_state;
var g = current.assignment_group.toString();
var grp = '8a5055c9c61122780043563ef53438e3'; // Hardware, the group this applies to
//gs.info("groupOnHoldDuration: s = " + s + ", g = " + g);
if ((g != '') && (g == grp)) {
// gs.info("groupOnHoldDuration: processing: " + current.number);
// Check for existing metric instance
var mi = new MetricInstance(definition, current);
// gs.info("groupOnHoldDuration: checking for: " + definition.name + ", current: " + current.number);
if (mi.metricExists()) {
// gs.info("groupOnHoldDuration: Found existing metric to close, state: " + s + ".");
// close metric, if state is no longer 'On Hold'
if (s != 3)
closeMetric(definition.sys_id, current.sys_id);
}
else {
// start metric, if state is now 'On Hold'
if (s == 3)
createMetric(mi);
}
}
function createMetric(m_i) {
var mir = m_i.getNewRecord();
// mir.start = current.sys_update_on;
mir.start = new GlideDateTime();
mir.calculation_complete = false;
mir.value = 'On Hold';
// gs.info("groupOnHoldDuration: creating metric to start: " + mir.start);
mir.insert();
}
function closeMetric(def_sys_id, inc_sys_id) {
// var mir = m_i.metricExists(); just returns T/F, so query for existing record
var gmr = new GlideRecord('metric_instance');
gmr.addQuery("id", inc_sys_id);
gmr.addQuery("definition", def_sys_id);
gmr.addQuerry('value', 'On Hold');
gmr.query();
// gs.info("groupOnHoldDuration: closeMetric: found: " + gmr.getRowCount() + " records for id: " + inc_sys_id);
if (gmr.next()) {
gmr.end = new GlideDateTime();
gmr.duration = gs.dateDiff(gmr.start.getDisplayValue(), gmr.end.getDisplayValue());
gmr.calculation_complete = true;
// gs.info("groupOnHoldDuration: closeMetric: setting end: " + gmr.end);
gmr.update();
}
}
I don't know what a PA script is.