- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 03:10 AM - edited 02-29-2024 04:55 AM
Hi all,
I have a requirement to track when a customer was not updated through additional comments on their incident. I know this can be done by creating a new field, however this is not an option for us.
I have created a database view to capture incidents and metric instances, and I have created two metric definitions, one to track when an additional comment is added to an incident (Incident Commented), one tracks when the incident was created (New Incident - to track incidents without comments).
I need the New Incident instance to end when a new Incident Commented metric instance is created (so basically one will end the other).
How can I achieve this please?
So far I have written this code in the new Incident definition but it's not working to set the end field:
if (current.incident_state == 1) { // New
createMetric();
}
function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;
var gnr = mi.getNewRecord();
gnr.start = current.sys_created_on;
gnr.insert();
}
function closeMetricDuration() {
var gr = new GlideRecord('metric_instance');
gr.addQuery('id', current.sys_id);
gr.addQuery('calculation_complete', false);
gr.addQuery('definition_name', 'Incident Commented');
gr.query();
while (gr.next()) {
gnr.end = gr.start;
gnr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gnr.calculation_complete = true;
gnr.endDuration();
}
if (gr.metricExists()) {
closeMetricDuration(current);
}
}
I've found this post which had a similar requirements but I cannot get the code to work in mine and the new Incident is not creating a new instance in New Incident.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 01:50 AM
I solved this myself. For whoever is looking at a similar use case, I've left the "New Incident" script empty, and added this code to the "Incident commented" metric definition:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 01:50 AM
I solved this myself. For whoever is looking at a similar use case, I've left the "New Incident" script empty, and added this code to the "Incident commented" metric definition: