
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2018 05:57 PM
Hi Team,
The OOTB Metric Instances for 'Field Value Duration' only calculate the duration and not the 'business duration'.
These use the 'MetricInstance' Script Include to set the required values and I can't figure out how to add the 'business duration' field.
The code 'gr.business_duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());' will allow me to actually save a value in the 'business_duration' field, but obviously it's not he correct value.
I need to load a schedule and wanted to use code received from Dennis (on another of my posts) but I can't seem to get it working at all. Code I'm trying is below:
var gdurCalendar = GlideDateTime.subtract(gr.startgetDisplayValue(), gr.end.getDisplayValue()); // Calculate calendar duration
var gdurBusiness = new GlideDuration(gdurCalendar); // Calculate business duration - If we can't find a valid schedule, use the calendar duration
var gsBusiness = new GlideSchedule('dcf6c8fedb5d7e007d1bfa0dbf9619db');
gdurBusiness = gsBusiness.duration(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.business_duration = gdurBusiness;
Any help is appreciated as I'm probably mixing up a bunch of stuff as I'm not an advanced coder.
I've also logged a ticket with HI as research shows this may be a bug as well.
Thanks Carl.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2018 06:07 PM
try
// Create schedule
var gsBusiness =new GlideSchedule('dcf6c8fedb5d7e007d1bfa0dbf9619db');
// Get duration based on schedule
gr.business_duration = gsBusiness.duration(gr.start.getGlideObject(), gr.end.getGlideObject());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2018 04:28 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2018 05:32 PM
Hi Mike - turns out I was having a 'muppet' moment... I had replaced the table name 'metric_instance' with the sys_id or name of the metric definition....
once I rectified that things were humming along...
Thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2018 10:32 AM
Do we need to add this in the script include -MetricInstance Or in the script section in Metric definition?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2018 03:40 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2019 11:41 PM
Hi Mike!
I am trying to make sense of this solution. Is the "gr"-variable related to the metric instance?
I have a requirement to calculate "assigned to"-duration based on a schedule. Outside of the schedule hours the field value duration "clock" needs to be paused.
Eg: An assignee accepts an incident and the metric is created with a "start"-value. The business day ends (based on defined schedule) and the next business day, the assignee reassigns the incident to another assignee, which sets the "end" value on the Metric Instance. In this case, I want to calculate only the assigned to duration within the business day hours.
Is this possible?