I currently have a list of options in a choice that is very long. User wants to consolidate the list, but removing values from the option set in the table isn't an option. I'm attempting to hide certain options, but am running into the error "Cannot read properties of null (reading 'getOptions')" when the form loads. The option set is all lowercase and is spelled correctly, but I replaced it with "my_optionset".
Here is my code:
function hide_options(executionContext) {
// get form context
var formContext = executionContext.getFormContext();
// Get options from lead source.
var optionValues = formContext.getControl('my_optionset').getOptions();
// Remove options from optionValues if not "Bid Notification System", "Contract Renewal", "Direct Sale", or "Marketing Generated"
for (let i = 0; i < optionValues.size; i++) {
if (optionValues[i] == "Bid Notification System" || optionValues[i] == "Contract Renewal" || optionValues[i] == "Direct Sale" || optionValues[i] == "Marketing Generated" || optionValues[i] == null) {
continue;
}
else {
formContext.getControl('ena_leadsource').removeOption(optionValues[i]);
}
}
}