Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Limit date selection in date field

vcaracci75
Tera Expert

I would like to set up a date field (variable name: "access_expiration_date") so that if a user tries to select a date greater than six months from the current date, they will get an error message. I would imagine this is an easy script to write, but I'm a fairly new admin and I'm not quite sure how to do it.

Thanks!

Vince

15 REPLIES 15

Sama4
Kilo Expert

Did you manage to address this issue ?


No, I'm still working on it.


Harneet Sital
Mega Sage
Mega Sage

Hi Vince,



I would rather suggest you to use UI policy than a client script because of the execution order in which they both run, UI Policy runs first.


Here is the way to achieve your requirement,



Create a new UI policy on the date field as below   :


find_real_file.png



Click on the advance checkbox, in the script part write the following code :



function onCondition() {


alert('End date cannot 6 months from current date');


g_form.setValue('u_end_date','');


}


find_real_file.png



Let me know if you need any further help on this.


How will that code only limit selection to Tuesday's and Thursdays?



Thanks,



Vince


Vince,



This won't. I thought requirement was only a validation over a period of 6 months.


You will need to go with a onChange client script if you want selection only on Tuesdays and Thursdays. Add 180 days to the current date and check the day of the week if it's not Tuesday or Thursday alert a popup.