On your code you forgot to replace gr with current.

try below

current.active = false;
if (current.closed_by.nil())
	current.closed_by = gs.getUserID();
if (current.closed_at.nil()) {
	current.closed_at = gs.nowDateTime();
	current.calendar_duration = gs.dateDiff(current.opened_at.getDisplayValue(),current.closed_at.getDisplayValue(),false);
	current.calendar_stc = gs.dateDiff(current.opened_at.getDisplayValue(),current.closed_at.getDisplayValue(),true);
	var gsBusiness = new GlideSchedule('c509a299db122300e020f8fdbf9619f8'); //sysid of schedule
	// Get duration based on schedule
	current.business_duration = gsBusiness.duration(current.opened_at.getGlideObject(), current.closed_at.getGlideObject());
	current.business_stc = gsBusiness.duration(current.opened_at.getGlideObject(), current.closed_at.getGlideObject());
}

View solution in original post