How to Display Forms Based on Option Set Values in Dynamics 365

How to Display Forms Based on Option Set Values in Dynamics 365

Dynamics 365 allows organizations to create multiple forms for the same table. In many business scenarios, users need to see different forms depending on the value selected in an Option Set (Choice field).

Using JavaScript, you can automatically switch between forms based on the selected option value, creating a more personalized and efficient user experience.

Why Display Different Forms?

Business Scenario

Suppose you have a Customer Type option set with the following values:

Based on the selected value, a different form should be displayed automatically.

JavaScript Example

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

```
var customerType =
    formContext.getAttribute("new_customertype")
               .getValue();

if(customerType === 100000000)
{
    formContext.ui.formSelector.items
        .get("Customer Form ID")
        .navigate();
}
else if(customerType === 100000001)
{
    formContext.ui.formSelector.items
        .get("Vendor Form ID")
        .navigate();
}
```

} 

The script checks the selected option set value and redirects the user to the appropriate form.

Important: Users must have access to all target forms. Form switching will not work if security roles do not permit access.

Implementation Steps

  1. Create multiple forms for the table.
  2. Publish all forms.
  3. Create a JavaScript Web Resource.
  4. Add the script to the form.
  5. Register the function on Form Load.
  6. Register the function on Option Set On Change event.
  7. Pass execution context.
  8. Test form switching behavior.

Common Use Cases

Best Practices

Advantages of Dynamic Form Switching

Key Takeaways