- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 07:03 PM
Hello, I have an incident metric (script for the metric below). The metric calculates the duration of the time it took for the ticket, from creation to the ticket being assigned to a group. The metric has an unused "Value" field, as pictured in the screenshot. How can I update the script to convert the duration of minutes, hours, and days to an XX.xx numeric value? Converted into just hours. Then, populate that number in the value.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 08:45 PM
You can try something like this
var dur_seconds = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue(),true);
gr.value = Math.round(dur_seconds / 3600)+' Hrs';
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 08:45 PM
You can try something like this
var dur_seconds = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue(),true);
gr.value = Math.round(dur_seconds / 3600)+' Hrs';
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 09:32 PM
Hi @Scott29
try this:
// Variables available
// current: GlideRecord - target incident
// definition: GlideRecord - (this row)
var g = current.assignment_group;
if (g != "")
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.u_time_to_assignment_group;
// Calculate duration in milliseconds
var durationMillis = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue(), true);
// Convert duration to hours and round to two decimal places
var durationHours = Math.round((durationMillis / (1000 * 60 * 60)) * 100) / 100;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.value = durationHours; // Store duration in hours as a numeric value
gr.calculation_complete = true;
gr.insert();
}
…………………………………………........................................................................................
Mark it helpful 👍and Accept Solution ✅!! If this helps you to understand.
…………………………………………........................................................................................