Business duration is not getting calculated correctly.business rule used for calculation is

Khushboo8
Tera Contributor

if (current.state == 7) {
  // incident state is closed so
  // 1. mark the task as inactive
  // 2. set the closed by to current user if not supplied
  // 3. set the closed time to now if not supplied
  current.active = false;
  if (current.closed_by.nil())
        current.closed_by = gs.getUserID();
  if (current.closed_at.nil())  
        current.closed_at = gs.nowDateTime();

  // now we want to update the fields that indicate the time
  // or duration of this incident from open to close.   We keep
  // track of duration as a glide_duration value (dd hh:mm:ss) and
  // as a pure number of seconds.
  //
  // Both calendar time and business time are maintained

  current.business_duration =
      gs.calDateDiff(
            current.opened_at.getDisplayValue(),
            current.u_resolved.getDisplayValue(),
            false);

  current.business_stc =
      gs.calDateDiff(
            current.opened_at.getDisplayValue(),
            current.u_resolved.getDisplayValue(),
            true);

  current.calendar_duration =
      gs.dateDiff(
            current.opened_at.getDisplayValue(),
            current.u_resolved.getDisplayValue(),
            false);

  current.calendar_stc =
      gs.dateDiff(
            current.opened_at.getDisplayValue(),
            current.u_resolved.getDisplayValue(),
            true);

}

6 REPLIES 6

Rajender1
Mega Sage

Hello Khushboo,


you can use TIME WORKED FIELD


look at this link Timing Functionality - ServiceNow Wiki


tarleen
Tera Contributor

There is   out of the box Business rule (mark_closed & mark_resolved) available for calculating the business duration .



In this business rule, function calDateDiff is used. it calculates the difference between two dates using the default calendar.


For default calender ,take a look under System Policy> SLA> Calendars.


You can even schedule the calender according to the requirement.


Business duration is the time from open to closure, in regards to the primary SLA calendar. So if your Calendar is 8 hour day Mon-Fri, and a incident opens start on Mon and closes end of Wed, it would display as 24 hours.






Hi Tarleen,


How to calculate business duration for a schedule?