Validate Past date selection on a field

vartika
Tera Contributor

Hi All,

I have a requirement to validate a catalog variable, not to allow user to select any past date. Someone please tell me the working code of it using Client script and Script Include. 

Thanks in Advance!

7 REPLIES 7

Sai_Charan_K
Kilo Sage

Hi @vartika  ,

Try creating an on change client script on this date variable such that you check the difference between current date and the date variable and if the difference is less than 0 then you clear the date variable and display error message stating date shouldn't be a past date.

 

Please mark this as "Helpful" and "Correct" if this helped you in anyway.

 

Thanks and Regards,

K. Sai Charan

Sr. ServiceNow Developer 

Deloitte India 

Hi @Sai_Charan_K ,

 

The basic i know, but the difficulty is user will be having different date format compared to current. If you can provide any working code that will be helpful.

 

Thanks

Aniket Chavan
Tera Sage
Tera Sage

Hello  @vartika  

 

You can achieve this simply with UI policy and no code will be needed.

Please refer the below images and let me know if you have any further questions.

AniketChavan_1-1727246007304.pngAniketChavan_2-1727246021518.png

 

AniketChavan_0-1727245957083.png

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.


Regards,
Aniket

 

Hi @Aniket Chavan

I have achieved that way but i am not sure that's a good practice to do or not. But with this i also want that using Client script and Script include also.