"mark_resolved" business rule

sapna_sagar
Kilo Expert

Hi , I was checking "mark_resolved" OOO BR .

Can someone please explain me why calendar_duration   and business_duration are different even they are using same function with same

start date and end date and same default calendar.

Business duration is calculation by default calendar but why not calendar_duration   ?? we have used same for calculating both.

setResolutionFields();

function setResolutionFields() {

    if (current.resolved_by.nil())

          current.resolved_by = gs.getUserID();

    if (current.resolved_at.nil())

          current.resolved_at = gs.nowDateTime();

   

    // Update the fields that indicate the time and duration of this incident from open to resolve.

    // 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.

   

    var dataChange = current.opened_at.changes() || current.resolved_at.changes();

    var opened = current.opened_at.getDisplayValue();

    var resolved = current.resolved_at.getDisplayValue();

    if (dataChange || current.business_duration.nil())

          current.business_duration = gs.calDateDiff(opened, resolved, false);

   

    if (dataChange || current.business_stc.nil())

          current.business_stc = gs.calDateDiff(opened, resolved, true);

   

    if (dataChange || current.calendar_duration.nil())

          current.calendar_duration = gs.dateDiff(opened, resolved, false);

   

    if (dataChange || current.calendar_stc.nil())

          current.calendar_stc = gs.dateDiff(opened, resolved, true);

}

1 ACCEPTED SOLUTION

darius_koohmare
ServiceNow Employee
ServiceNow Employee

Actually, they are different function calls. (dateDiff vs calDateDiff).


Business resolve time generally takes into account business hours (that is defined in a calendar/schedule), e.g. if you operate 8 hour days, 3 days would be reflected as 24 hours.



Resolve time is the full value running 24x7 irrespective of a calendar. 3 days would be reflected as 72 hours.



As a side note, the default calendar used is the first one returned in a list.


View solution in original post

3 REPLIES 3

darius_koohmare
ServiceNow Employee
ServiceNow Employee

Actually, they are different function calls. (dateDiff vs calDateDiff).


Business resolve time generally takes into account business hours (that is defined in a calendar/schedule), e.g. if you operate 8 hour days, 3 days would be reflected as 24 hours.



Resolve time is the full value running 24x7 irrespective of a calendar. 3 days would be reflected as 72 hours.



As a side note, the default calendar used is the first one returned in a list.


Ahh..Yes...



Can you tell me if i need to use schedule in same function   then what will be the function ?


If you want to calculate a duration given a schedule, check this out as it has the answer:


Useful scheduling scripts


if(current.incident_state==6){
 
var dur = calcDurationSchedule(current.opened_at,current.sys_updated_on);
  current
.u_resolved_duration= dur;

 
function calcDurationSchedule(start, end){
 
// Get the user  
 
var usr =new GlideRecord('sys_user');
  usr
.get(gs.getUserID());
 
// Create schedule - pass in the sys_id of your standard work day schedule and pass in the users timezone
 
var sched =new GlideSchedule('08fcd0830a0a0b2600079f56b1adb9ae',usr.time_zone);
 
// Get duration based on schedule/timezone
 
return(sched.duration(start.getGlideObject(), end.getGlideObject()));}