start date should be today + 2 business days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 08:51 PM
Posting this again as I could not get it working:
Hi
Can someone please help me with catalog client script (on change) and script include
I have a date variable in the new hire form.
The requirement is users should only be allowed to select the "start date" as current date + 2 business days (exclude sat-sun).
Example: If I'm filling the form today , (Oct 11) the start date should be Oct 14 or further. User should not be be able to select an ealier date and should give an error " Invalid date"
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2023 11:56 PM
Hi @Thomas99
It took me a while to come back and check on this 🙂
I tried the below code and it worked fine for me even during the weekend.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('ValidateDate');
ga.addParam('sysparm_name', 'dateValidation');
ga.addParam('sysparm_date', newValue);
ga.getXML(CallBack);
function CallBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'true') {
g_form.setValue('lpar_refreshed', '');
g_form.showErrorBox("lpar_refreshed", "pls select atleast 48hrs or more from now");
}
}
}
Please mark my answer helpful and accept as solution if it helped you 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 06:58 AM
Hello @Thomas99
You should calculate the duration based on a schedule to get the business duration. Try the below script in script include.
var ValidateDate = Class.create();
ValidateDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
dateValidation: function(){
var selected_date = new GlideDateTime(this.getParameter('sysparm_date');
var today = new GlideDateTime();
var schedule = new GlideSchedule();
schedule.load('090eecae0a0a0b260077e1dfa71da828'); // loads "8-5 weekdays excluding holidays" schedule
var duration = schedule.duration(today, selected_date);
var days = duration.getRoundedDayPart();
if(days > 2){
return 'true';
}
return 'false';
},
type: 'ValidateDate'
});