Glide schedule Subtract

kailashthiyagar
Kilo Guru

The below script does add date based 8-5 Business days and it works fine. But i have a requirement, where it needs to do the subtract. It didnt work.. Could anyone of you help?

 

var date = this.getParameter('sysparm_date');
var dueDays = this.getParameter('sysparm_dueDays');

dueDays = 3;
var nowgdt = new GlideDateTime(date);
// The name of the schedule

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

var dueWorkingHours = 9;

// The amount of time we want for the duration
var dueSeconds = dueDays*dueWorkingHours*60*60;

var leadTime = new GlideDuration(dueSeconds*1000);

//gs.error('Kailash' + leadTime);
// Calculate the Due Date!
var dueDateGdt;
var schedRec = new GlideRecord('cmn_schedule');
if (schedRec.get('name', myScheduleName)) {
var sched = new GlideSchedule(schedRec.sys_id);
//leadTime *=-1;
//gs.error('Lead time' + leadTime);
dueDateGdt = sched.add(nowgdt, leadTime, '');
}
var time = dueDateGdt.getDisplayValue();
1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

This thread should help

 

https://community.servicenow.com/community?id=community_article&sys_id=c4ccae25dbd0dbc01dcaf3231f961...


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

14 REPLIES 14

SanjivMeher
Kilo Patron
Kilo Patron

This thread should help

 

https://community.servicenow.com/community?id=community_article&sys_id=c4ccae25dbd0dbc01dcaf3231f961...


Please mark this response as correct or helpful if it assisted you with your question.

Thanks Sanjiv @sanjivmeher. There were too issues. one in scoped application, 

 

  usrTZ = startDateBeg.getUserTimeZone(); 

 

This line is not working and i have to use gs.getSession().getTimeZoneName(); and another thing is there is class DurationCalculator he has used and he mentioned in that class, he defined the two methods.. Is it the script include name? and if so it doesnt makes sense.. rit?

It is out of box function

 

https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_re...

 

The script include 'ScheduleUtils' utilizes DurationCalculator, which is defined out of box


Please mark this response as correct or helpful if it assisted you with your question.

This is what i got when i logged the error

 

ReferenceError: "DurationCalculator" is not defined.