
asifnoor
Kilo Patron
Options
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 01-13-2020 09:25 PM
In this article, today i will share you a code snippet which will allow user to to select only a weekday from any of the date field in your form. If weekend is selected, we will show an error message.
For this, we need 2 scripts
Client Script: OnChange to select the changed value
Script Include: To check if the date is a weekday or weekend.
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);
var response = ga.getXMLAnswer(parseResponse);
function parseResponse(answer) {
if(answer == 'true') {
g_form.showFieldMsg('expected_start','Select any weekday','error',true);
}
}
}
Script Include
var selectWeekday = Class.create();
selectWeekday.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isWeekDay: function() {
var selected_date = this.getParameter("sysparm_date");
var d = new GlideDateTime(selected_date);
//Monday -1 sunday -7
if(d.getDayOfWeekLocalTime() > 5){
return true;
} else {
return false;
}
},
type: 'selectWeekday'
});
Let me know if you have any questions in the comments below.
Mark the article as helpful and bookmark if you found it useful.
- 4,045 Views