- 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-05-2025 05:18 AM
Glad to know.
Can you share the final script so that it helps other community members?
How are you setting the timezone when the BR/script run since I just updated the timezone in User preferences and it gave correct output?
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:50 AM
Hello @Sneha_18
The possible reason could be that the schedule with the ID "090eecea0a0b260077e1dfa71da828" does not exist or is not correctly configured. Please verify this by navigating to System Definition > Schedules in ServiceNow and ensuring the schedule is present and properly set up.
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar