Need help with business duration calculation on a catalog task

JR Guieb
Tera Expert

I have have a business rule to calculate the duration and business duration on the Catalog Task table.  The duration calculates fine but the problem I found was that the business duration wasn't calculating correctly.  I later found that my script was call the system calendar.  I changed the system calendar to reflect our work hours and holidays correctly but my problem is how do I recalculate all the previous catalog task's business durations.

 

This is my business rule script

TABLE : Catalog Task [sc_task]

current.active = false;
if (current.closed_by.nil())
current.closed_by = gs.getUserID();
if (current.closed_at.nil()) {
current.closed_at = gs.nowDateTime();
current.business_duration = gs.calDateDiff(current.opened_at.getDisplayValue(),current.closed_at.getDisplayValue(),false);
current.business_stc = gs.calDateDiff(current.opened_at.getDisplayValue(),current.closed_at.getDisplayValue(),true);
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);
}

 

1 ACCEPTED SOLUTION

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

5 REPLIES 5

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