Force Mandatory Variable

Community Alums
Not applicable

Hi Connections,

 

I have a variable. Safe Updating with three choices, when safe updating is selected, I want to push user to fill any ONE of the below variables, Standard User Role OR Safe Manager Role.  How can I achieve this. any suggestions... to show that two variables i have created UI policy to appear on the form when safe updating is selected....

 

Rafmine_0-1699483036531.png

 

appreciate any help.

 

Best Regards,

Rafmine.

 

 

 

18 REPLIES 18

Brad Bowman
Kilo Patron
Kilo Patron

Visually, you can either make both variables mandatory when they are visible via the same UI Policy actions, or leave them as not mandatory - realizing either option is misleading from a UX perspective as both variables are not mandatory, it's just a visual indication.  To enforce that one of the variables is populated you would use an onSubmit Catalog Client Script.  In pseudocode, if Safe Updating = Add User to Safe, and Standard User Role is blank, and Safe Manager Role is blank, show an error message and prevent the form submission.  Give the script a shot and let me know if you get stuck on the syntax.

Community Alums
Not applicable

Hi Brad,

Thats will be a great move, can you help me with the code plz.

 

Best Regards,

Rafmine.

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Community Alums ,

 

Can you try something like this, please use proper backend names of the variable

 

function onSubmit() {
   //Type appropriate comment here, and begin script below

   var abc = g_form.getValue('add_user_safe');
   var stdRole = g_form.getValue('standard_user_role');
   var safeMgrRole = g_form.getValue('safe_manager_role');


   if(abc == 'true' && stdRole == '' && safeMgrRole == ''){
	alert('Kindly fill the Standard User Role Value & Safe Manager Role Value');
	return false;
   }else{
	return true;
   }
   
}

 

Thanks,

Danish

 

 

Community Alums
Not applicable

Hi Danish,

 

Thank you for replying to my post, appreciate it...

My scenario is that I have push user to at least fill one variable value. 

Standard User Role  OR Safe Manager Role ... I tried your code, it is pushing user to fill both the variables... can you help me with that...
 
User can put values in both the variables depends on user, but user has to put atleast one value in any of the variables..