I need help with the business duration calculation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2017 11:50 AM
I don't understand how to set it up or how it is supposed to work OOB. I changed the calendar schedule to match our schedule, but the field still shows incorrect information. We are trying to get business duration on tasks assigned to our desktop group, and will eventually attach an SLA to that, but right now, we just need a simple calculation of opened - closed = business duration. Why doesn't it work??? Any thoughts? I do not know Java at all, so please no scripting. I just want to know how to get that OOB field to work correctly. One task was opened on 2017-01-06 10:05:10, and closed at 2017-01-23 08:43:16 and the business duration says 4 Days 1 Hour 38 Minutes?? That is not even possible. Any help would be greatly appreciated. We are looking at sc_task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2017 02:12 PM
Hi Suzanne,
Unfortunately, to get ServiceNow to set the business_duration (and business_stc) fields correctly, you're probably going to need to do some scripting.
The OOB functionality uses calDateDiff to calculate the business duration and that function references the Calendar (sys_calendar) table. According to online documentation, this table is Legacy, though ServiceNow continues to use it out of the box not just here but in other places as well (e.g. Notification Subscriptions). According to ServiceNow Engineering the documentation about legacy sys_calendars was only written about SLAs, though this seems contrary to the online documentation. There are at least 3 open enhancement requests that I know of related to ServiceNow's continued use of the legacy calDateDiff() function and the legacy Calendars table (FTASK28449 FTASK28451 FTASK28453). The bottom line is that ServiceNow has no current plans to address this, so if you want the business_duration and business_stc fields to calculate correctly, you're probably going to have to do some scripting.
One of the biggest issues with the calDateDiff function is that there's no way to specify which Calendar record to use. Documentation states that it will reference the 'default' Calendar record, but there's no way to 'flag' a Calendar record as the Default, and in our testing, it didn't reliably use the same one every time.
Do you happen to have more than one record on the Calendars table? If so, it's possible that calDateDiff was using a Calendar record you weren't expecting it to use, and causing the calculation you saw. You might be able to work around this by only having one Calendar record, but you might also have good reasons for having more than one, as we do.
We ended up having to update several OOB business rules that used calDateDiff, converting them to using Schedules instead. There's an example of how to start down that path here: http://wiki.servicenow.com/index.php?title=Calculate_Duration_Given_a_Schedule
I wish I had an easy no-scripting answer for you. Especially if you have more than one Calendar record, I can't think of a way around doing some scripting.
-Joe