Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Disable/Hide an option set value

Posted on by Microsoft Employee

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

  • Ang111 Profile Picture
    Ang111 25 on at
    RE: Disable/Hide an option set value

    Can you please let me know how?

  • Suggested answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: Disable/Hide an option set value

    Hi  Ang111,

    You can not do it other than JS.

    If I answer your question then please mark it as verified.

    Let me know if I can provide you with more details.

    Thanks
    Regards,

    Abdul Wahab
    Power Platform & Customer Engagement Developer/Lead/Solution Architecture/Project Manager
    Direct/WhatsApp:+923323281237
    E-mail: abdulwahabubit@outlook.com
    Skype: abdul.wahabubit
    Linkedin: www.linkedin.com/.../

  • Ang111 Profile Picture
    Ang111 25 on at
    RE: Disable/Hide an option set value

    Hi,

    I have the same inquiry, can I do it somehow else other than using JavaScript?

  • Saddamk206 Profile Picture
    Saddamk206 777 on at
    RE: Disable/Hide an option set value

    Hi,

    Also can try this:-

    for (var i = 0; i < Xrm.Page.getAttribute("FieldName").getOptions().length; i++)
    {

    Xrm.Page.getControl("FieldName").removeOption(Xrm.Page.getAttribute("FieldName").getOptions()[i].value);
    }

  • Community Member Profile Picture
    Community Member Microsoft Employee 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);
    
    
  • Sukh Gill Profile Picture
    Sukh Gill 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

  • Suggested answer
    Neil Parkhurst Profile Picture
    Neil Parkhurst 10,725 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

  • awalters Profile Picture
    awalters 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...

  • GrizzlyGlen Profile Picture
    GrizzlyGlen 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?

  • Suggested answer
    CRASH Profile Picture
    CRASH 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").

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans