- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2023 02:20 AM
Hi All,
How to restrict the user from selecting past dates. I used below methods for restricting user from selecting past dates. It works fine if use past date of current month. And doesn't work for previous and future months.
i,e if current date is 19-3-2023, below methods works fine according for any date in current month. But if i select 20-2-2023,its not showing error instead its accepting it. And if i select 18th in next month its showing error "not to select past date"
1. Used ui policy
Execute if true:
function onCondition() {
g_form.clearValue("date_variable");
g_form.showFieldMsg("date_variable", "Previous date not allowed" , "error");
}
2.Used catalog client script
var curDate = ("0" + new Date().getDate()).slice(-2) + '-' + ("0" + (new Date().getMonth() + 1)).slice(-2) + '-' + new Date().getFullYear();
if (curDate > newValue) {
alert("Selected date shouldnt be less than current date");
g_form.clearValue('start_date');
}
Thanks in Advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2023 05:13 AM - edited 03-19-2023 05:13 AM
Hi Gujan,
Its working fine now, how to ensure that end date should always be greater than start date using ui policy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2023 05:43 AM
Hi @Sachin G K1
Please check below article. You can use the Last mentioned scenario in the below article:-
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2023 05:53 AM
Hi Gunjan,
I tried it before, i am using sandiego version. it didn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2023 12:27 AM
you can apply UI policy condition as if start date - is more than - 0 days - after - end date then clearValue() and an error message.
Regards,
Pradnya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2023 02:30 AM
Hi Sachin,
Unsure, your need for script but this can be handled with no code at all. Mark has a solution for it. Please check, link

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2023 03:40 AM
You cannot write a client script that makes hard-coded assumptions about date format and expect it to work reliably because users have the ability to change their date format.