Show/Hide choices of a multiple choice field based on two fields of Company chosen

Mouktik_B
Tera Contributor

There are two fields under each Company (X and Y). 

There are 2 choices under a multiple choice type field Relationship.
IF x is true , then first choice autopopulates under one field 
IF y is true , then second choice autopopulates .

 

What to do in client scriopt?
Already created a script include and a client script

 

4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

Do you have screenshot of the form?

-Anurag

Mouktik_B_0-1708007407100.png

The two fileds inside Company are vendor and customer , if that company chosen has vendor checked then this choice of vendor should show up and likely the next.

Here is aa  sample script: 

Put this in a onchange client script, it should run on the field when you update the company relationship field

 

if(g_form.getValue('<company Relationship Variable Name>') == '<Company Choice Value>')
{
g_form.setDisplay('<Company variable name that should be visible>', true); // show company field
g_form.setDisplay('< Vendor variable name that should be visible>', false); // hide vendor  field
}
else if(g_form.getValue('<company Relationship Variable Name>') == '<VendorChoice Value>')
{
g_form.setDisplay('<Vendor variable name that should be visible>', true); //show vendor field
g_form.setDisplay('<Company variable name that should be visible>', false); //hide company field
}

 

PS. make sure that UI type field on the client script is set to 'All' so that it runs on portal and native ui both.

 

-Anurag

Ayushi12
Mega Sage

Hi @Mouktik_B 

Use g_form.removeOption('variable_name','value','label'); to remove options
Use g_form.addOption('variable_name','value','label'); to add options
Use g_form.setValue ('variable_name','value'); to set the variable value

Please mark this response as correct or helpful if it assisted you with your question.