RE: Show/Hide Multiple Fields Based on Option Selection Using Javascript
Hi,
Please note, following line returns the INTEGER value of the selected option:
const productOfferingValue = formContext.getAttribute("new_opportunityproductoffering").getValue();
You can get the integer value from the OptionSet field properties, for the label Hedge Fund Administration, there must be an integer value.
We need to compare in the if condition for this integer value, your function should look like this:
function HideFields(executionContext)
{
const formContext = executionContext.getFormContext();
const productOfferingValue = formContext.getAttribute("new_opportunityproductoffering").getValue();
if (productOfferingValue === 1000001) // replace 1000001 with the value of Hedge Fund Administration option
{
formContext.getAttribute("new_someotherfield1").setVisible(false);
formContext.getAttribute("new_someotherfield2").setVisible(false);
formContext.getAttribute("new_someotherfield3").setVisible(false);
}
else
{
formContext.getAttribute("new_someotherfield1").setVisible(true);
formContext.getAttribute("new_someotherfield2").setVisible(true);
formContext.getAttribute("new_someotherfield3").setVisible(true);
}
}
To get the integer value for the Hedge Fund Administration option:
- Open the solution and expand Entities -> Opportunity -> Fields.
- Double click on the Opportunity Product Offering field to open the properties.
- Under the Type section, if the Use Existing Option Set is "Yes" click on Edit to see the options, otherwise you will see the options on the same screen.
- Get the Value of Hedge Fund Administration option:
Please note, in the if condition, we will compare the value without commas.