- 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 11:26 PM
Thanks, it's workable.
Can you please help me one more ? I need start date cannot be before today.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2021 11:30 PM
Sure, but its better to raise a separate question, and close this thread since original question has been answered. This will now confuse the future readers.
Hope you understand!!
Thanks,
Aman
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2021 11:30 PM
Hi,
you can re-use the same script by writing onChange on Start date?
update as this with just message change
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("Start date should not be after End date"));
g_form.setValue('end_date','');
}
}
I would recommend using onSubmit instead of 2 onChange client script
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 11:34 PM
Ankur please don't mess up the thread!!
Thanks,
AMAN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2021 11:38 PM
I don't think separate question is required as the follow up question relates to the same original question about the validation ..!!
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader