Using GlideSchedule to define business duration using metric instance
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 05:45 PM - edited 08-16-2023 05:48 PM
hello,
Can anyone assist me with my script that will populate the business duration while using a metric instance? I'm able to create the endDuration, but can't pass the businessDuration to it.
I'm looking for help to input variable duration as the endDuration.
This is what I'm working with below. Thanks in advance!
if (current.state < 3){
answer = false;
mi.endDuration();
closeDurations(mi.current);
}
function closeDurations(current) {
var gr = new GlideRecord('metric_instance');
gr.addQuery('id', current.sys_id);
gr.addQuery('calculation_complete', false);
gr.addQuery('definition.type', 'field_value_duration');
gr.addQuery('definition', 'ddbf5a931bac7d905fa4fdd91d4bcb91');
gr.query();
while (gr.next()) {
businessDuration(current.start, gr.end);
var businessDuration = function(open,closed){
var startDate = new GlideDateTime(open);
var endDate = new GlideDateTime(closed);
var schedule = new GlideSchedule();
schedule.load('15baf29fdb73c4d0062480e2399619cb'); // loads "24x5 weekdays" schedule
var duration = schedule.duration(startDate, endDate);
gs.info(duration.getDurationValue()); // gets the elapsed time in schedule
duration = (duration.getNumericValue() /(1000 * 60 * 60)) / 24;
gs.info(duration);
return duration;
};
var definition = new GlideRecord('metric_definition');
definition.get(gr.definition);
var mi = new MetricInstance(definition, current);
mi.endDuration();
}
}
0 REPLIES 0