- 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 02:30 AM
Hi @Sachin G K1 ,
Please share snapshot of your UI policy conditions.
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 02:44 AM
hi Gunjan,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2023 03:09 AM
Hi @Sachin G K1
Your UI Policy looks fine, if you are applying both client script and UI policy at the same time the it might conflict, please make the client script false and try to apply all conditions from UI policy itself and then check.
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: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