[Service Portal] How to validate start and end dates in portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2020 09:05 AM
Hi! Appreciate your advice about how to correctly put a date validation in the servical portal.
What I'm trying to achieve:
There are 2 dates in the portal form:
Start Date
End Date
Validation: The end date should not be prior the start date
I tried that using below client script but it did not work.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var first=g_form.getValue('u_effective_date_of_leave');
var last=g_form.getValue('u_last_worked_day');
if(last<=first){
alert("Last day worked should be on or prior to effective date of leave");
g_form.setValue('u_effective_date_of_leave','');
//Type appropriate comment here, and begin script below
}
}
Anything I'm missing? thanks in advance
- Labels:
-
Case and Knowledge Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2020 09:16 AM
Hi there,
Have you considered using a (Catalog) UI Policy to achieve date validations? There's almost no-code needed to achieve date validations this way. Have a look at an article I wrote on this:
No Code date validations thru (Catalog) UI Policies
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2020 09:18 AM
And a copy/paste from the article:
Comparing two entered dates with each other. Date 2 should not be before Date 1 (image, planned end date should not be before planned start date)
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2020 09:52 AM
Hello Mark! Thanks for sharing this.
I used the Catalog UI Policy route for the 2 date fields I'm creating (comparing 2 entered dates). So what would I add then in the Catalog UI Policy actions for this one? Like where do I enter the error message.
Thanks,
Paul

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2020 10:00 AM
Have a look at the article, you can generate the message through the Script fields if true, if false.
No catalog UI policy actions needed.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field