
- 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
‎06-06-2018 07:58 AM
Hi Carl and Mike,
I am trying to accomplish the same thing you are doing with calculating the business duration for some of the incident metrics that are available out of the box. I don't understand why the field is business duration field is available on the table for metrics, yet it is not being calculated out of the box!
I see you marked this as an accepted solution, but I am not following how you were able to do this. Did you create a business rule that calculates the business duration, or another script include or something? If you wouldn't mind sharing your solution, that would be greatly appreciated!
Thank you,
Mike

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 08:09 AM
Business duration is not calculated OOTB so you can create business rule or scheduled script to do so.
Below is scheduled job script that you can use to fill in business duration (make sure to replace sysid of schedule)
var gr = new GlideRecord("metric_instance");
gr.addEncodedQuery('end!=NULL^business_duration=NULL');
gr.autoSysFields(false); // so that the records don't have system updates
gr.query();
while(gr.next()) {
var gsBusiness =new GlideSchedule('dcf6c8fedb5d7e007d1bfa0dbf9619db');
// Get duration based on schedule
gr.business_duration = gsBusiness.duration(gr.start.getGlideObject(), gr.end.getGlideObject());
gr.setWorkflow(false);
gr.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 09:03 AM
Thank you so much Mike!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 08:11 PM
This is great, how would I limit the records updated to records over the last year? I don't want this to take a long time and tie up my instance. Any help is appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2020 02:46 PM