[Date] field to only allow current date and future dates (No past dates)

imranybs
Kilo Contributor

Hi,

I've the following script that allows not to select any past dates. But I would like to modify this to select the current date and any future dates. Please advise. Thanks ! function onChange(control, oldValue, newValue, isLoading, isTemplate) {                 if (isLoading || newValue == '') {                                 return;                         }                         var d = getDateFromFormat(newValue, g_user_date_format);                 var today = new Date();                 if (d < today) {                                 alert('The date value cannot be before the current date and time. Please correct.');                 g_form.clearValue("effective_date");                 }         }

1 ACCEPTED SOLUTION

arnabwa
Giga Guru

Hi Imran and All,



Let us make this very very simple.


We will make a UI Policy with this condition :


curr1.PNG


here manufacture_date is the field which I'm checking if a past date is not entered. Replace it with your own variable name.



And now we just write a 2 line code in the "Script" part of the same UI Policy :


curr2.PNG



And that's it guys. We are good to go. We need not use any client scripts because for form validations the best practice is to use UI Policies. Using client scripts would have performance issues.


Please let me know if you have further doubts.



Thanks,


Arnab


View solution in original post

25 REPLIES 25

imranybs
Kilo Contributor

Done, thanks again for your help.


Well Imran, You marked your own answer Correct. I meant to mark the solution of that person to be marked correct who actually gave you the correct answer.


Anyway thanks and Happy working !


imranybs
Kilo Contributor

Corrected, thanks!


prasannalk
Tera Contributor

This functionality is not working in service portal. 

True, this doesn't seem to be working on the SP (New York).

If I change the condition to this:
find_real_file.png

that will actually trigger my script:
find_real_file.png

 

But if I choose this:
find_real_file.png

 

The script never gets run!