We may often not want to show all the options from an OptionSet in the form.
Here, we can hide options from OptionSet using JavaScript in Dynamic 365 CRM.
Let’s see the below scenario.
We have a Job Title field on the form where we have some of the options in OptionSet. We need to hide one of the options from the OptionSet field.
JavaScript Code
JobRole = {
hidejobtitleOption: function (context) {
“use strict”; debugger;
var formContext = context.getFormContext();
var gradeOptionSet = formContext.getControl(“crmonce_jobtitle”);
if (gradeOptionSet !== null) {
gradeOptionSet.removeOption(878010000);
}
}
};
Now, we want to hide the “Science Teacher” option from OptionSet when a form loads.
Now, with the above information shown, we can go and hide the option “Science Teacher”.
With the help of JavaScript Code, we can hide the options that we don’t need to display on the form.
Below is the code we need to register the OnLoad of the form and pass the Context as the first parameter. Next, we need to call the function on OnLoad, as shown in the below screenshot.
Now, when we load the form, the “Sciences Teacher” options are no longer visible.
For any help or queries contact us on info@crmonce.com or +91 9014146800
October 17, 2024
October 11, 2024