Calculating Business Duration Issues
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-24-2024 12:10 PM
Hello, we have a business rule that calculates the business duration based on a set schedule (working hours from 06:30 - 18:30 CST). This, for the most part has been working correctly, but I'm noticing some issues if the ticket is created before or after working hours. In this case, the business duration will calculate to 0 seconds and not account for the actual business time. The parent scheduled referenced in the script is on the US/Central timezone as well as our system timezone the same, unsure of why it's unable to calculate some of the business durations properly.
the BR script is an after update when the state moves to closed or cancelled
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2025 01:35 PM - edited ‎03-14-2025 01:37 PM
This worked for me. I created a new schedule in "cmn_schedule" and a schedule entry for it.
onBefore Business Rule
On Insert or Update
if (current.state == 3 || current.state == 4 || current.state == 7) {
current.active = false;
if (current.closed_by.nil())
current.closed_by = gs.getUserID();
if (current.closed_at.nil()) {
current.closed_at = gs.nowDateTime();
// 'Business Duration 8-5 Weekdays' Schedule
var schedule = new GlideSchedule("73342611975cee10a15eb5400153af85");
var duration = schedule.duration(current.opened_at.getGlideObject(), current.closed_at.getGlideObject());
current.business_duration = duration;
current.calendar_duration = gs.dateDiff(current.opened_at.getDisplayValue(), current.closed_at.getDisplayValue(), false);
}
}