In Date variable I should select only 7 business days after dates and it should not allow to select any saturdays and sundays
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2022 08:17 PM
HI
I have created a new date variable, For this date varable i need validations like, I should select only 7 business days after dates and it not allow to select saturdays and sundays
Can any one help me on this.
Thanks
Prasad.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2022 06:29 PM
Hi The below script will do the both. Even if you select sat/sun it will not calculate as a part of business day. It will throw an error.
For example if you select fri,sat,sun,mon. It will count only for fri and mon since we are using business day schedule
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var msg = 'Proposed date cannot be prior to 7 business days from Request Date';
var ga = new GlideAjax('dateValidation'); // SI name
ga.addParam('sysparm_name','validateDate'); //SI function
ga.addParam('sysparm_needed_by',newValue);
ga.getXML(callBack);
function callBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert("answer"+answer);
//Calculating 9 hour schedule to check 7 working days 24*7=168
if(parseInt(answer)>= 54){
g_form.hideFieldMsg('joining_date'); // variable name
}
else{
alert("else");
alert(msg);
g_form.clearValue('joining_date');
}
}
}
Script Include
validateDate: function(){
var dc = new DurationCalculator();
dc.setSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); // this is the sys_id of 8-5 weekday schedule in the instance.
dc.setTimeZone('GMT');
var dur = dc.calcScheduleDuration(gs.now(),this.getParameter('sysparm_needed_by'))/3600;
return dur.toString();
},
Harish