- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 11:30 PM
Hi everyone,
I need to create a date/time type variable.
And in the date picker, the date should be only future dates and allow only upto 90 days.
Thanks in advance for your help!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 05:01 AM
Hi @Southsayer ,
Then you can use the 2 onchange client scripts.
1. Create onchange client script on start date and use below script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (g_form.getValue('start_date') != '' && g_form.getValue('end_date')) {
var start = new Date(g_form.getValue('start_date')); //your start date variable name
var end = new Date(g_form.getValue('end_date')); //your end date variable name
if (start > end) {
g_form.addErrorMessage('Verify start date and end date');
return false;
}
}
}
2. Create other onchange client script on end date and use below script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (g_form.getValue('start_date') != '' && g_form.getValue('end_date')) {
var start = new Date(g_form.getValue('start_date')); //your start date variable name
var end = new Date(g_form.getValue('end_date')); //your end date variable name
if (end < start) {
g_form.addErrorMessage('Verify start date and end date');
return false;
}
}
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 02:58 AM
Hi Pavan,
It was helpful. I have two date/time variables start date and end date.
start date ----- future dates only, allow only up to 90 days and duration up to 90 days.
end date ----- future dates only, allow only up to 90 days and duration up to 90 days.
how can I use catalog policy so that the end date should be always greater than the start date and the maximum duration between the start date and end date should be up to 90 days?
thanks a lotttt for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 03:59 AM
Hi @Southsayer ,
1. end date ----- future dates only, allow only up to 90 days and duration up to 90 days.
for above step 1 you need to create UI policy which i shared for start and create another UI policy for End date and use same conditions.
2. To do Start date and end date validation below onsubmit client script.
function onSubmit() {
if (g_form.getValue('start_date') != '' && g_form.getValue('end_date')) {
var start = new Date(g_form.getValue('start_date')); //your start date variable name
var end = new Date(g_form.getValue('end_date')); //your end date variable name
if (end < start) {
g_form.addErrorMessage('Verify start date and end date');
return false;
}
}
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 04:10 AM
Hi Pavan, thanks once again.
on submit will only work when I submit the request form for the catalog item. however, I need to validate them right away as soon as the end date is entered. How can I do that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 05:01 AM
Hi @Southsayer ,
Then you can use the 2 onchange client scripts.
1. Create onchange client script on start date and use below script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (g_form.getValue('start_date') != '' && g_form.getValue('end_date')) {
var start = new Date(g_form.getValue('start_date')); //your start date variable name
var end = new Date(g_form.getValue('end_date')); //your end date variable name
if (start > end) {
g_form.addErrorMessage('Verify start date and end date');
return false;
}
}
}
2. Create other onchange client script on end date and use below script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (g_form.getValue('start_date') != '' && g_form.getValue('end_date')) {
var start = new Date(g_form.getValue('start_date')); //your start date variable name
var end = new Date(g_form.getValue('end_date')); //your end date variable name
if (end < start) {
g_form.addErrorMessage('Verify start date and end date');
return false;
}
}
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 05:59 AM
Hi,
still no luck. I wonder why it is not working using the catalog on change client scripts.
Is there any way to do it using the Catalog UI policy?
thanks in advance....