Many times, you might not want to show all Options from an OptionSet while it is on a form. So, here’s how you can hide Options from OptionSet using JavaScript in Dynamics 365 CRM!
Scenario
Let’s see the below scenario where these are the options you already see –
- You see, there are 3 options for this OptionSet on Contact Form.
- Now, you want to hide “Platinum” as an option when a Form loads. So, let’s see how this done.
- Now, we can use this information to hide the Option Platinum. We’ll write JS script on the OnLoad of the Contact form.
JS Code
Here’s a JS code sample which will hide the options which you don’t need to display.
- Below is the code which you need to register OnLoad of the Contact form and also pass the Context as first parameter –
- And when you register it OnLoad, it should look like below –
Code:
oContactCustomization = {
hidePlatinumGrade: function (context) {
"use strict"; debugger;
var formContext = context.getFormContext();
var gradeOptionSet = formContext.getControl("new_grade");
if (gradeOptionSet !== null) {
gradeOptionSet.removeOption(3);
}
}
};
Here, you get the OptionSet using getControl(); method and then use the variable to then have removeOption(<OptionSet Value>);
Result
Now, when you load the form, you’ll see the option is no longer visible –
Hope this helps!
Here are some Power Automate posts you want to check out –
- Select the item based on a key value using Filter Array in Power Automate
- Select values from an array using Select action in a Power Automate Flow
- Blocking Attachment Extensions in Dynamics 365 CRM
- Upgrade Dataverse for Teams Environment to Dataverse Environment
- Showing Sandbox or Non Production Apps in Power App mobile app
- Create a Power Apps Per User Plan Trial | Dataverse environment
- Install On-Premise Gateway from Power Automate or Power Apps | Power Platform
- Co-presence in Power Automate | Multiple users working on a Flow
- Search Rows (preview) Action in Dataverse connector in a Flow | Power Automate
- Suppress Workflow Header Information while sending back HTTP Response in a Flow | Power Automate
- Call a Flow from Canvas Power App and get back response | Power Platform\
- FetchXML Aggregation in a Flow using CDS (Current Environment) connector | Power Automate
- Parsing Outputs of a List Rows action using Parse JSON in a Flow | Common Data Service (CE) connector
- Asynchronous HTTP Response from a Flow | Power Automate
- Validate JSON Schema for HTTP Request trigger in a Flow and send Response | Power Automate
- Converting JSON to XML and XML to JSON in a Flow | Power Automate
Thank you!