Restrict user to select past date in catalog item

Sachin G K1
Kilo Sage

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

1 ACCEPTED SOLUTION

Hi Gujan,

 

Its working fine now, how to ensure that end date should always be greater than start date using ui policy

View solution in original post

9 REPLIES 9

Gunjan Kiratkar
Kilo Patron
Kilo Patron

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

hi Gunjan,

 

SachinGK1_0-1679219055365.png

 

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

Hi Gujan,

 

Its working fine now, how to ensure that end date should always be greater than start date using ui policy