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:
    • /

For example:

    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!/api_doc?v=helsinki&id=r_GS-calDateDiff_S_S_B.

Also, be aware of the related problem KB0623761: Instance may run out of memory when the gs.calDateDiff function is called to evaluate two dates that cross a daylight savings time change.

Steps to Reproduce


  1. Navigate to Incident > All.
  2. Personalize the list by adding the following columns to the list view:
    • Open
    • Closed
    • 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/ 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.

  1. 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.
  2. 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

Seen In

Geneva Patch 4
Geneva Patch 5
Geneva Patch 6
Geneva Patch 6 Hot Fix 2
Geneva Patch 7
Helsinki Patch 1
Helsinki Patch 2
Helsinki Patch 3 Hot Fix 3
Helsinki Patch 4
SR - ITOM - Discovery and Service Mapping - 201908

Fixed In

Istanbul Patch 7
Jakarta Patch 1

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2020-01-03 01:33:28