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.

Restrict the Date field from allowing future dates

sarahkapasi
Giga Expert

How can I restrict a date field from allowing to enter future date?

Thank you,

Sarah 

1 ACCEPTED SOLUTION

Paul Curwen
Giga Sage

Try this On Change Client Script for your date field that you want to check:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

   if (isLoading || newValue === '') {

      return;

   }

            //current date

            var currentDateObj = new Date();

            var currentDateStr = formatDate(currentDateObj, g_user_date_format);

            var currentDateNum = getDateFromFormat(currentDateStr, g_user_date_format);

            var startDateNum = getDateFromFormat(newValue, g_user_date_format);

 

            if (startDateNum > currentDateNum) {

                        alert(“Date is in the future”);              

                        g_form.clearValue("your_date_field");

                        return false;

            }

}

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul

View solution in original post

5 REPLIES 5

Hi Rosy,

Looks like it's not  supported in Service Portal. Your not the only one to have run into this issue see:

 

link

 

this may help: link

 

Regards,


Paul 

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul