- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2018 04:33 PM
Hi all,
I would be grateful if someone would tell me how to run a Metric definition based on a Schedule, for instance, "8-5 weekdays" schedule. My goal is to disable the Metric definition from generating Metric Instances outside working hours.
Parsing and comparing the time manually is my last option.
Your help is highly appreciated.
Thanks,
Mazin
Solved! Go to Solution.
- Labels:
-
Event Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2018 05:29 PM
Other option is to calculate business duration. I did it using below script and report of the business duration field.
Scheduled Job - Script
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-08-2018 05:29 PM
Other option is to calculate business duration. I did it using below script and report of the business duration field.
Scheduled Job - Script
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-09-2018 03:48 AM
Thank you, it worked just perfect 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 07:00 AM
This doesn't seem to be working for my instance, has something changed with the duration calculation? Just getting 0 seconds for all entries.