- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2021 09:27 PM
Hello,
I need help. I am trying to use Catalog UI Policy to set the condition on the end date field. What I need is the end date cannot be before start date.
The field is "date" not "date/time"
I applied the condition as below for "end_date_of_visit" is more than 0 days after "starting date of visit" and use the client script BUT it doesn't work. The end date of visit field still can fill in the date before starting date.
Not sure that for this case, it's wrong on the condition I set or from the client script ?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2021 10:33 PM
Hi,
Have you tried an alternative with the onchange client script on end_date.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var dFormat = g_user_date_format;
var end = getDateFromFormat(g_form.getValue('end_date'),dFormat);
var sDate=getDateFromFormat(g_form.getValue('start_date'),dFormat);
if(end<sDate)
{
alert(getMessage("End date should not be before Start date"));
g_form.setValue('end_date','');
}
}
Please mark Correct✅/helpful???? if applicable, thanks!!
Aman
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2021 10:34 PM
Please check the script I shared just now
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2021 10:32 PM
you can also use onSubmit Catalog Client Script
Applies to Catalog Item
UI Type - ALL
function onSubmit(){
var start = new Date(g_form.getValue('start_date_of_visit')).getTime();
var end = new Date(g_form.getValue('end_date_of_visit')).getTime();
if(end < start){
getMessage("End date should not be the day before the Start date", function(msg){
g_form.showErrorBox('end_date_of_visit', msg);
g_form.clearValue('end_date_of_visit');
});
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2021 12:44 AM
Hi,
As already mentioned and for better code maintenance you can use single onSubmit client script instead of 2 onChange client scripts.
I have already shared the script.
Did you get a chance to check on that?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2021 10:33 PM
Hi,
Have you tried an alternative with the onchange client script on end_date.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var dFormat = g_user_date_format;
var end = getDateFromFormat(g_form.getValue('end_date'),dFormat);
var sDate=getDateFromFormat(g_form.getValue('start_date'),dFormat);
if(end<sDate)
{
alert(getMessage("End date should not be before Start date"));
g_form.setValue('end_date','');
}
}
Please mark Correct✅/helpful???? if applicable, thanks!!
Aman

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2021 11:23 PM
Thanks for marking the response as correct, please close all your threads by marking the appropriate response as correct.
Thanks,
Aman