How to remove mandatory status if a reference field has no options

Travis Michigan
Mega Sage

Is there an easy way to check if a reference field has no options available to select, and so make it so the field is no longer mandatory?

 

I would like to have a check on the service portal so after the building is changed it checks to see if the floor has any options, and if not then it changes the fields mandatory to false.

1 ACCEPTED SOLUTION

Edgar10
Tera Guru

Try this on onLoad client script

 

 

var f1 = g_form.getControl("FieldName");
		
if(f1.options.length != 1 ){ //check if the dropdown has choices
	g_form.setMandatory("FieldName",false);
	
}

 

View solution in original post

3 REPLIES 3

Mohit_Gupta
Tera Guru
Tera Guru

Hi @Travis Michigan ,

 

You need to run your script on load and need to check the records in the reference table by using filter if there is any if you got any record then you can mark as mandatory if not then don't.

 

I hope this helps 

Please mark my answer correct if this helps you 

Thanks

Mohit

Edgar10
Tera Guru

Try this on onLoad client script

 

 

var f1 = g_form.getControl("FieldName");
		
if(f1.options.length != 1 ){ //check if the dropdown has choices
	g_form.setMandatory("FieldName",false);
	
}

 

Travis Michigan
Mega Sage

To get it to do precisely what I wanted I ended up using it as an onChange but that worked.  Thank you so much @Edgar10 !