Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Client Script to prevent user from selecting past date not working

Khalnayak
Kilo Sage

Hi all,

 

I have a catalog client script to prevent users from selecting a date in the past. But it is not fully working.

 


It now stops me from selecting any date, and error appears. past or future date.

 

Below is my script on a onChange client script.

function onChange(control, oldValue, newValue, isLoading) {
   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) { 
		g_form.addErrorMessage("Date cannot be in the Past");
		g_form.clearValue("day_month_year_start_time");
		return false;
	}
   
}

 

please advise

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @Khalnayak ,

Please use my below working Scripts,just replace your variables.

onChange Catalog Client Script:-

1) Client Script for Future Date Validation:-

SandeepDutta_0-1677592607797.png

 

2) Past Date Validation:-

SandeepDutta_1-1677592607540.png

 

3) Common Client Callable Script Include:- 

SandeepDutta_2-1677592607532.png

 

4) Script Include Code;-

SandeepDutta_3-1677592607547.png

 

 

View solution in original post

6 REPLIES 6

Community Alums
Not applicable

Hi @Khalnayak ,

Please use my below working Scripts,just replace your variables.

onChange Catalog Client Script:-

1) Client Script for Future Date Validation:-

SandeepDutta_0-1677592607797.png

 

2) Past Date Validation:-

SandeepDutta_1-1677592607540.png

 

3) Common Client Callable Script Include:- 

SandeepDutta_2-1677592607532.png

 

4) Script Include Code;-

SandeepDutta_3-1677592607547.png

 

 

Thanks, please can you copy paste the scripts here too so I can copy it

Community Alums
Not applicable

Kindly write the code from the screenshot as my instance is offline right now @Khalnayak 

Hi Sandeep, i have setup as above but it does not work