How to Hide Options from Option Set in Dynamics 365 CRM

How to Hide Options from Option Set in Dynamics 365 CRM

Option Sets (Choice fields) in Dynamics 365 CRM often contain multiple values, but not every option is relevant in every business scenario. Using JavaScript, you can dynamically hide specific Option Set values and display only the choices that users need.

This improves user experience, reduces data entry errors, and ensures users select only valid options based on business requirements.

Why Hide Option Set Values?

Hide a Specific Option

Use the removeOption() method to hide an Option Set value.

function hideOption(executionContext)
{
    var formContext =
        executionContext.getFormContext();

    formContext.getControl("new_status")
               .removeOption(100000001);
}

The specified option value will no longer appear in the dropdown list.

Hide Multiple Options

You can remove multiple values from the same Option Set.

function hideMultipleOptions(executionContext)
{
    var formContext =
        executionContext.getFormContext();

    var control =
        formContext.getControl("new_status");

    control.removeOption(100000001);
    control.removeOption(100000002);
    control.removeOption(100000003);
}

Hide Options Based on Another Field

You can dynamically remove values based on user selections.

function filterOptions(executionContext)
{
    var formContext =
        executionContext.getFormContext();

    var category =
        formContext.getAttribute("new_category")
                   .getValue();

    if(category === 100000001)
    {
        formContext.getControl("new_status")
                   .removeOption(100000003);
    }
}
Important: Register the function on Form Load and On Change events to ensure options are filtered correctly whenever users interact with the form.

Implementation Steps

  1. Create a JavaScript Web Resource.
  2. Add the script to the form.
  3. Register the function on Form Load.
  4. Register the function on relevant On Change events.
  5. Pass execution context.
  6. Save and publish customizations.
  7. Test dropdown behavior.

Common Use Cases

Best Practices

Key Takeaways