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?
- Show relevant fields for specific business scenarios
- Reduce form complexity
- Improve user experience
- Increase data quality
- Support multiple business processes
Business Scenario
Suppose you have a Customer Type option set with the following values:
- Customer
- Vendor
- Partner
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
- Create multiple forms for the table.
- Publish all forms.
- Create a JavaScript Web Resource.
- Add the script to the form.
- Register the function on Form Load.
- Register the function on Option Set On Change event.
- Pass execution context.
- Test form switching behavior.
Common Use Cases
- Customer vs Vendor forms
- Employee vs Contractor forms
- Product category forms
- Region-specific forms
- Service request types
- Industry-specific data collection
Best Practices
- Keep form designs consistent.
- Use meaningful option set values.
- Test security role access.
- Avoid excessive form switching.
- Document form IDs and logic.
- Use executionContext and formContext.
Advantages of Dynamic Form Switching
- Personalized user experience
- Reduced form clutter
- Better usability
- Improved business process alignment
- Higher data quality
Key Takeaways
- Dynamics 365 supports multiple forms per table.
- JavaScript can dynamically switch forms based on option set values.
- Form personalization improves user experience.
- Security roles must allow access to target forms.
- Dynamic form switching supports complex business scenarios effectively.