The following three base system business rules still use the legacy calDateDiff() function.
- 'mark_closed' on Incident and Problem tables:
- 'mark_resolved' on Incident table, only present if the Incident Management - Core plugin com.snc.incident_management is activated:
if (dataChange || current.business_duration.nil())
current.business_duration = gs.calDateDiff(opened, closed, false);
if (dataChange || current.business_stc.nil())
current.business_stc = gs.calDateDiff(opened, closed, true);
The calDateDiff() function uses deprecated calendars. As a result, the mark_closed and mark_resolved business rules are returning incorrect results.
The ServiceNow product documentation states that calendars are legacy and schedules should be used instead. For more information, see calDateDiff, String startDate, String endDate, Boolean numericValue at https://developer.servicenow.com/app.do#!/api_doc?v=helsinki&id=r_GS-calDateDiff_S_S_B.
Steps to Reproduce
- Navigate to Incident > All.
- Personalize the list by adding the following columns to the list view:
- Business duration
- Business resolve time
Note that some of the Business duration and Business resolve time entries are incorrect.
If you are able to upgrade, review the Fixed In field to determine the versions with the core fix deployed (glide/src/com/glide/schedule/GlideCalendar.java). The fix does not retroactively update previously calculated business duration on Tasks/Incidents, but the business rules will invoke the new core code.
Use the workaround described below for Enterprise instances that cannot be upgraded yet. This is not applicable to Express instances.
Any existing call to calDateDiff needs to be replaced with logic that calculates duration according to a schedule.
Create a schedule or use an existing base system schedule.
Be sure to choose the schedule time zone that is best suited to the environment:
- Floating makes use of the system.
- Defining a time zone, such as US/Pacific, ensures that the duration is calculated according to the schedule spans applied in the US/Pacific time zone.
Copy the sys_id of the chosen schedule and modify the script for the mark_closed and mark_resolved business rules as follows:
// Default Workday 8-5 Floating schedule. Replace with sys_id of the schedule to be used 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; // Stores value in seconds. The numeric value function returns a value in milliseconds, hence divide by 1000 current.business_stc = duration.getNumericValue() / 1000;
Related Problem: PRB680207