date variable

abhisek
Tera Contributor

Hi All,

I have a date variable 'xyz' which value is getting auto populated based on other 2 variable's values but still not read only. When the value of the date variable 'xyz' is not empty then I need to restrict the user to select any date which is greater than the current value of that date variable xyz that means user can select any date till the date which is already getting auto populating but not greater than that. 

I want to do it using on change client script.

 

Can you please help me out.

Thanks in advance.

 

Regards,

Abhisek Chattaraj.

 

 

 

15 REPLIES 15

@abhisek  

I already informed without hidden variable it's not possible

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

I have implemented it with hidden variable.

Thanks&Regards,

Abhisek Chattaraj

@abhisek  

Glad to know.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

I had implemented this with hidden variable as you suggested but issue is when variable xyz is getting auto populated with the greater date than the previous auto populated date value then also it is throwing the error message.

But using on submit catalog client script it is working.

 

Regards,

Abhisek Chattaraj.

MukkamalaM
Tera Contributor

@abhisek  

Step1: Create a hidden variable with name as 'date1' and store the auto populated date in that variable.
Step 2: Use the following On Change script for the variable which user can change:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   var existing_date=g_form.getValue('date1'); //get auto-populated date from hidden variable
   if(newValue>existing_date){  //if date changed by user is greater than the existing
   g_form.clearValue('user_changed_date'); //clears the date
   g_form.addErrorMessage('Date should not be greater than the auto-populated date');
   }
   
   }
 
Mark this helpful if it works!

Regards
Mounika