- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 05:41 PM
Hello Community,
I need to limit the delivery date for a request to at least 1 week out from the date the item is requested. Below is the client script I'm using. It works for dates that are 7-8 days out from the request submission date, but does not work for dates that are further out than that. If today's date is 11/6, then it should allow me to request delivery on 11/28, but it will not accept that date. I get the message "Allow 1 week for delivery" even though 11/28 is easily farther out than 1 week.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 06:12 PM
@Jeremy F_ Try updating your script as follows and see if it works for you.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var cdt=g_form.getValue('delivery_completion_date'); //Date/Time field
var dttype='day'; //format of time - minute, hour, day, default is seconds
var ajax=new GlideAjax('ClientDateTimeUtils'); //OOB Script Include
ajax.addParam('sysparm_name','getNowDateTimeDiff');
ajax.addParam('sysparm_fdt',cdt);
ajax.addParam('sysparm_difftype',dttype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(parseInt(answer) <=7){
alert("Allow 1 week for delivery.");
g_form.setValue('delivery_completion_date','');
}
}
}
In case if the above change doesn't work then please share your script include code which is comparing the dates.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 06:12 PM
@Jeremy F_ Try updating your script as follows and see if it works for you.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var cdt=g_form.getValue('delivery_completion_date'); //Date/Time field
var dttype='day'; //format of time - minute, hour, day, default is seconds
var ajax=new GlideAjax('ClientDateTimeUtils'); //OOB Script Include
ajax.addParam('sysparm_name','getNowDateTimeDiff');
ajax.addParam('sysparm_fdt',cdt);
ajax.addParam('sysparm_difftype',dttype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(parseInt(answer) <=7){
alert("Allow 1 week for delivery.");
g_form.setValue('delivery_completion_date','');
}
}
}
In case if the above change doesn't work then please share your script include code which is comparing the dates.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 12:20 PM
Any date past 7 days from the current date should be available to select, but it doesn't work that way. If I choose a day 14 days out, it won't allow me to select that date.