The G
The G

Reputation: 83

Hide/remove Option set value using JavaScript for CRM Dynamics 365?

working on a tutorial at home with Microsoft Dynamics 365 CRM, to hide a Option Set Value from a dropdown, however this dropdown also is used on a Business Process Flow, I dont want to delete the Option Set Value, just hide it i.e. removeopotion/hide.

Im trying to use JavaScript to hide/remove this, however Im very new to JS and dont really understand it, my code is below:

function hideOptions(executionContext) {
    var formContext = executionContext.getFormContext();
    
    if (formContext.ui.getFormType() == 1 || formContext.ui.getFormType() == 2 ) {
        var pickList = formContext.Page.getControl("statuscode");
        pickList.removeOption("Test1");
        pickList.removeOption("Test2");
        pickList.removeOption("Test3");
        pickList.removeOption("Test4");
    }
}

Please advise.

Upvotes: 0

Views: 17800

Answers (2)

The G
The G

Reputation: 83

I fixed this now thank you guys, was missing the correct schema name name "header_statuscode"

function hideOptions(executionContext) {

var formContext = executionContext.getFormContext();

 if (formContext.ui.getFormType() == 1 || formContext.ui.getFormType() == 2 ) {
 
 var pickList = formContext.getControl("header_statuscode");
 pickList.removeOption(1);
 pickList.removeOption(2);

 }
}

Upvotes: 0

Arsen
Arsen

Reputation: 372

You should provide the numeric value in the removeOption method.
As it's said in microsoft docs

formContext.getControl(arg).removeOption(value);
value - Number - The value of the option you want to remove.

Upvotes: 3

Related Questions