Looks like this is working:



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()){


  var dur = calcDurationSchedule(current.opened_at, current.resolved_at);


  current.business_duration = dur;


  }



  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);


}




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()));


}