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.

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

Community Alums
Not applicable

Hi Danish,

 

Yes on selection of 'Add User to Safe' I'm getting those 2 fields correct...

below is the Screeshot for variable.. data Type is Multiple Choice...

 

Rafmine_1-1699507821192.png

I appreciate your time and efforts...

 

 

@Community Alums ,

 

All seems to be good. Can u put an alert for all 3 variables safeupdt,stdrole & safemgr role. wht is coming when u submit. Something like this

 

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');
alert("Safe Update :- " + safeupdt);
alert('stdRole :- '+stdRole);
alert('safeMgrRole:- '+safeMgrRole);

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

 

 

Also i hope the UI type is set to ALL on the client script, if you are running it on portal.

 

Thanks,

Danish

 

 

Community Alums
Not applicable

Hi Danish,

 

Yes, I have selected UI type is set to ALL on the client script, if you are running it on portal.

Below is the screenshot for your reference..

 

Rafmine_0-1699510533004.png

 

Rafmine_1-1699510635572.png

 

Rafmine_2-1699510732359.png

 

Rafmine_3-1699510826130.png

I really appreciate your time and support... 

 

Rafmine.

 

Community Alums
Not applicable

Hi Danish,

 

If I select the values in both the fields then only the form is getting submitted... check my below client script code...

Rafmine_0-1699511792557.png

 

have also tried with below code as well but no luck..

 

Rafmine_1-1699511864121.png

Rafmine.

Hi @Community Alums ,

 

Apologies. Plz try this.

 

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(safeupdt == "Add User to Safe"){
   if(stdRole == "" && safeMgrRole == "")){
	alert('Kindly fill the Standard User Role Value & Safe Manager Role Value');
	return false;
   }else{
	return true;
   }
   }
}

 

Thanks,

Danish