Quick Tip: Show and Hide Option Set Options in Dynamics 365 with JavaScript — Fredrik Engseth

Fredrik Engseth
3 min readFeb 26, 2024

In this quick tip, we’ll explore how to show and hide options within an Option Set field in Microsoft Dynamics 365 forms using JavaScript. This approach is particularly useful when you need to tailor the user interface based on specific conditions, such as user roles, field values, or any logic that requires a more dynamic form experience.

Use case

Imagine you have an Option Set field in your Dynamics 365 entity form that needs to adapt based on certain conditions. For example, certain options should only be available to users in specific roles or depending on the values of other fields on the form.

The JavaScript Solution

To achieve this, we can use a simple JavaScript function that leverages the form’s execution context to hide or show Option Set values dynamically. Here’s a basic script that demonstrates how to hide specific options based on a Demo Security Role, otherwise show all fields:

// Check if the sdk object exists in the global window scope; if not, create an empty object.
// This ensures that we're adding to an existing sdk object or initializing it if it doesn't exist.
var sdk = window.sdk || {};

// Immediately Invoked Function Expression (IIFE) to…

--

--

Fredrik Engseth

Developer | Dynamics 365 | Power Platform | Azure | Personal development | Investments | ☕ https://www.buymeacoffee.com/fredrikengseth