- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 02:47 AM
Why the business duration is resulting in 0 seconds where it should be 1 hour 19 minutes as I have used OOB
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 06:32 AM
check this link and it talks about using PlannedTaskAPI to calculate the duration
Calculate the business duration using a schedule
I ran the same script and in preferences set the timezone as GMT and it gave me the correct output
try {
var schedule = new GlideSchedule("08fcd0830a0a0b2600079f56b1adb9ae", );
var open = new GlideDateTime('2025-01-03 07:00:00');
var closed = new GlideDateTime('2025-01-03 09:19:00');
// Use closed_at for "mark_closed" business rule and resolved_at for "mark_resolved" business rule
var plannedTaskAPI = new SNC.PlannedTaskAPI();
var resp = plannedTaskAPI.calculateDuration(open.getDisplayValue(), closed.getDisplayValue(), '08fcd0830a0a0b2600079f56b1adb9ae');
var response = new JSON().decode(resp);
var duration = response.duration;
gs.info(duration);
} catch (ex) {
gs.info(ex);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 04:01 AM
is this a OOB BR script or a custom one?
Did you check OOB duration BR mark_closed on incident table?'
This KB will help you for business duration
How the Duration and Business Duration calculation works
something like this
var schedule = new GlideSchedule("38f8b6d2c0a801640075da0e39d47696");
// Use closed_at for "mark_closed" business rule and resolved_at for "mark_resolved" business rule
var duration = schedule.duration(current.opened_at.getGlideObject(), current.closed_at.getGlideObject());
// Stores value as a GlideDuration
current.business_duration = duration;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 05:38 AM
Hi @Ankur Bawiskar ,
I have created a business rule to calculate the business duration for the cases created for different timezone users for working hours as 8 am to 5 pm in their respective timezone using OOB schedule "8-5 weekdays excluding holidays" but it is populating as "0 seconds" even if the time falls under the schedule time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 05:41 AM
cases created for different timezone -> what do you mean by this?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 05:45 AM
@Ankur Bawiskar I mean the cases opened by, thanks!