- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2021 03:28 AM
How to restrict saturday and sunday using UI Policy when selecting the date field?(Only Business days should be selected)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2021 06:02 AM
I think you should mark this response as correct as that contains the script
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2021 03:21 AM
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);
}
}
}