How to validate the day of the date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2023 07:20 AM
In change request form the planned start date and planned end date should fall on Saturday.
When user selects the option 'CAB Required', the system allows the planned start and end dates only when any day of the date from planned start to end should be Saturday.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2023 07:38 AM
Hello @PRASHANTHI SATH
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("DaySat");
ga.addParam("sysparm_name","isSaturday");
ga.addParam("sysparm_date",newValue);
var response = ga.getXMLAnswer(parseResponse);
function parseResponse(answer) {
if(answer == 'false') {
alert('Please Select a Date on Saturday');
return false;
}
}
}
Script Include
var DaySat = Class.create();
DaySat.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isSaturday: function() {
var selected_date = this.getParameter("sysparm_date");
var d = new GlideDateTime(selected_date);
//Monday -1 sunday -7
if(d.getDayOfWeekLocalTime() == 6){
return true;
} else {
return false;
}
},
type: 'DaySat'
});
Plz mark my solution as Accept, If you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2023 07:50 AM
Hi,
You can auto populate the end date using below logic.
var gdt = new GlideDateTime("2021-12-01 12:00:00");//Thursday
var daystoBeAdded=6-parseInt(gdt.getDayOfWeekLocalTime());
gdt.addDays(daystoBeAdded);
gs.info(gdt)
gs.info(gdt.getDayOfWeekLocalTime())//if 6 then it is saturday
Thanks and Regards,
Saurabh Gupta