web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Disable/Hide an option set value

(0) ShareShare
ReportReport
Posted on by

We use option sets quite often. Regularly I get asked to change the values of these as business requirements change.

Is there a way to disable an option set value, or hide a value that is no longer available to use?

Eg.

  1. Option A
  2. Option B
  3. Option C

Option B is no longer available. Deleting 'Option B' will delete this value from records already using this value, which I do not want to happen.

A quick fix would be to write 'DO NOT USE - Option B', but this looks messy.

Has anybody got a solution for this.

Thanks in advance.

*This post is locked for comments

I have the same question (0)
  • renton Profile Picture
    205 on at
    RE: Disable/Hide an option set value

    Hi LouDLGC

    I think you can use JavaScript to change the option set value.

    1.get option set object

    var optionSet = Xrm.Page.ui.controls.get("your option set control name")

    2.get option set list

    var optionSetValues = optionSet.getAttribute().getOptions();

    3.clear option set object

    optionSet.clearOptions();

    4.add the value you want to show in the option set

    optionSetValues.forEach(function (element) {

     //some conditon

     ...

     optionSet.addOption(element);

     ...

    }

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at
    RE: Disable/Hide an option set value

    Hi,

    No option to disable it but you should be able to implement your requirement using removeOption for optionset using javascript, it won't remove option from db just will hide this option from the user so your existing db data is safe, you can refer below post for how to use it:

    crmdynamicblog.blogspot.ae/.../remove-item-from-picklist.html

    Thanks

  • Suggested answer
    nghieppham Profile Picture
    4,755 on at
    RE: Disable/Hide an option set value

    Hi LouDLGC,

    You cannot do that unless you remove from OOB customization tool.

    In the other way, you have to implement by client script as Reimei said.

    Regards,

  • Community Member Profile Picture
    on at
    RE: Disable/Hide an option set value

    Thanks for your answer.. It helped me to figure it out.

    I achieved what I needed to do with the following code:

    function UpdateOptionSet() {  
    
    var UpdateOptionSetCatA1 = Xrm.Page.ui.controls.get("new_idcategorya1");
    
       var CatA1 = UpdateOptionSetCatA1.getAttribute().getValue();
    
    if (CatA1 == null){
    
    Xrm.Page.getControl("new_idcategorya1").removeOption('xxxxxxx');
    
    }
    
    if (CatA1 != 'xxxxxxx'){
    
    Xrm.Page.getControl("new_idcategorya1").removeOption('xxxxxxx');
    
    }
    
    }
    

    So basically:

    • onload if the option set value is null it removes the value 'xxxxxxx' from the option set.
    • onload if the option set value is not equal to the value 'xxxxxxx' it removed the value from the option set.
    • onload it the option is equal to the value 'xxxxxxx' the value is displayed

    Cheers

  • Suggested answer
    CRASH Profile Picture
    2 on at
    RE: Disable/Hide an option set value

    Hi,

    Do you mind using JS? If not, use code written below on page OnLoad.

    Xrm.Page.getControl("optionsetfieldschemaname").removeOption("OptionsetValue").

  • GrizzlyGlen Profile Picture
    90 on at
    RE: Disable/Hide an option set value

    Like the JS option but the problem if you're using a Business Process Flow to capture the Optionset. The JS won't work on the BPF. Anyone come up with any creative ideas for this?

  • awalters Profile Picture
    3,079 on at
    RE: Disable/Hide an option set value

    It's not ideal, but in a similar circumstance we decided to just put the options into an entity and have a lookup, rather than do an option set.  That way we could disable/re-enable them, make notes about why, etc...

  • Suggested answer
    Neil Parkhurst Profile Picture
    10,727 User Group Leader on at
    RE: Disable/Hide an option set value

    You can interact with fields in the business process flow using JavaScript. I describe how to do it in this post ...

    neilparkhurst.com/.../javascript-work-with-fields-in-header-and-business-process-flow

    You can also (if required) have onchange or onselect events for the stages in you business process flow. Again I describe that here;

    neilparkhurst.com/.../javascript-add-code-on-business-process-flow-change-and-select

    And logic for adding / removing fields from the optionset is described here;

    neilparkhurst.com/.../javascript-control-optionset-values

  • Sukh Gill Profile Picture
    967 on at
    RE: Disable/Hide an option set value

    If you are constantly being asked to hide values or change, the best approach for this (no code) would be to create the option set as an entity (ENTITY A) and create the values as records (OPTION A, OPTION B, OPTION C).  Then on the record where you have the option set, create a lookup to the custom entity (ENTITY A).  So when records no longer need to be visible, you can just deactivate the record (which will not remove reference to existing records) and when the user clicks on the lookup view they only see active records. 

    Thanks
    Sukh

  • Community Member Profile Picture
    on at
    RE: Disable/Hide an option set value

    Example use Xrm.Page.getControl(..).addOption :

        var low = {value : 100000000, text : "Low"};
        var medium = {value : 100000001, text : "Medium"};
        var high = {value : 100000002, text : "High"};
    
        var pickList = Xrm.Page.getControl("control_name");
        var options = pickList.getOptions();
    
        for (var i = 0; i < options.length; i++) 
            pickList.removeOption(options[i].value);
    
        pickList.addOption(low);
        pickList.addOption(medium);
        pickList.addOption(high);
    
    

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
UllrSki Profile Picture

UllrSki 2

#3
SC-08081331-0 Profile Picture

SC-08081331-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans