How to use Schedules in a Workflow

carlocsa
Kilo Expert

Hi Experts,

I am working on a catalogue item that auto-creates a Change Request upon approval of a Request Item. The Start Date is   5 business days after the create date of the Change Request and should not land on a weekday or holiday. I will be using the '8-5 weekdays excluding holidays' Schedule. I need your expert opinion how I can do this in the workflow.

Thank you!

Carlo

5 REPLIES 5

Try this one.



// Get the datetime now


var nowGdt = new GlideDateTime();


// The name of the schedule


var myScheduleName = '8-5 weekdays excluding holidays';



// The basis of our calculation


var dueDays = 3;


var dueWorkingHours = 9;



// The amount of time we want for the duration


var dueSeconds = dueDays*dueWorkingHours*60*60;


var leadTime = new GlideDuration(dueSeconds*1000);



// Calculate the Due Date!


var dueDateGdt;


var schedRec = new GlideRecord('cmn_schedule');


if (schedRec.get('name', myScheduleName)) {          


        var sched = new GlideSchedule(schedRec.sys_id);


        dueDateGdt = sched.add(nowGdt, leadTime, '');


}



gs.log('The Due Date is: '+dueDateGdt.getDisplayValue());