How to restrict saturday and sunday using UI Policy when selecting the date field?(Only Business days should be selected)

Akhil42
Tera Contributor

How to restrict saturday and sunday using UI Policy when selecting the date field?(Only Business days should be selected)

1 ACCEPTED SOLUTION

I think you should mark this response as correct as that contains the script

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

15 REPLIES 15

khadar
Tera Contributor

Hi Ankur,

In my case, the variable type is the only date. I tried with the below script but it didn't work. Could share your inputs, to achiceve this.

Script include:

var selectWeekday = Class.create();
selectWeekday.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isWeekDay: function() {
var selected_date = this.getParameter("sysparm_date");
var d = new GlideDate(selected_date);
//Monday -1 sunday -7
if(d.getDayOfWeek() > 5){
return true;
} else {
return false;
}
},
type: 'selectWeekday'
});

 

Client script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Show error when weekend is selected
var ga = new GlideAjax("selectWeekday");
ga.addParam("sysparm_name","isWeekDay");
ga.addParam("sysparm_date",newValue);
alert(newValue);
var response = ga.getXMLAnswer(parseResponse);
function parseResponse(answer) {
if(answer == 'true') {
g_form.showFieldMsg('required_by_date','Select any weekday','error',true);
}
}
}