I am creating a script impacting 30-40 custom fields. Where the fields to display depends upon a custom field. For all the different combinations, I have to make a set of fields available and required. i.e.
If the trigger is set to India: only make fieldA, fieldB, and fieldC available and required.
else if the trigger is set to US: only make fieldB, fieldE, and fieldF available and required.
case "Create new chair":
dynField1.setHidden(false);
dynField1.setRequired(true);
dynField2.setHidden(false);
dynField2.setRequired(true);
dynField3.setHidden(false);
dynField3.setRequired(true);
break
case "Create new table":
dynField4.setHidden(false);
dynField4.setRequired(true);
dynField3.setHidden(false);
dynField3.setRequired(true);
dynField5.setHidden(false);
dynField5.setRequired(true);
break
There are more than 15 such cases. Additionally, with the change in the trigger field, all the non-relevant custom fields should be marked as hidden and optional.
As you see above, this code isn't the best looking or efficient codes. Is there a better way of doing this?
Regards
Upasna Bassi