In Date variable I should select only 7 business days after dates and it should not allow to select any saturdays and sundays

prasad8
Giga Expert

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.

5 REPLIES 5

Abhay Kumar1
Giga Sage
Hi Prasad, please check below article mentioned script to use for the same. https://community.servicenow.com/community?id=community_question&sys_id=bd0d8bf1db6a5018d5c4d9d9689619ee Hope this will help you.

Hi @Abhay Kumar ,

This is helpfull for only restricting weekends, here i need to one more funtionality like users select only 7 business days after dates from current date.

 

 

Thanks,

Prasad.

Hi find the below script. Onchange client script and Script Include

Make sure variable names are correct as per yours

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('ValidateNeededBy'); // 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);
//Calculating 9 hour schedule to check 7 working days 24*7=168
 if(parseInt(answer)>= 54){
 g_form.hideFieldMsg('start_on'); // variable name
 }
 else{
g_form.hideFieldMsg('start_on');
g_form.showFieldMsg('start_on',msg,'error');
g_form.setValue('start_on','');
 }
 }
}

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

Regards
Harish

HI @Harish KM ,

 

I need to both functionalities for same field

1. It shoud not allow to select next 7 business days 

2. It should not allow to select saturday and sunday any more

 

Thanks,

Prasad