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)

How to show only certain items in an option set.....

(0) ShareShare
ReportReport
Posted on by 26

Hello,

I have an option set field called Field B that has about 8 items in it.  When Field A = Football, I want only certain items to display, when Field A is something other than Football, I want all the options to display.  How can I do this?  I would prefer to do this in Java Script, just need some help writing it.

Hope this makes sense, thank you.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Nuno Profile Picture
    2,005 on at
    RE: How to show only certain items in an option set.....

    Hi,

    You must use this methods to achieve what you want:

    msdn.microsoft.com/.../gg334266.aspx

  • USA80 Profile Picture
    26 on at
    RE: How to show only certain items in an option set.....

    Can you show me what this would look like in a script by chance?

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: How to show only certain items in an option set.....

    Hello,

    I believe you're looking for Dependent Optionset - msdn.microsoft.com/.../gg594433.aspx

  • USA80 Profile Picture
    26 on at
    RE: How to show only certain items in an option set.....

    Would I need all of this?

  • USA80 Profile Picture
    26 on at
    RE: How to show only certain items in an option set.....

    would it be something like this or am I way off?

    function RecordTypeOnChange()

    {

    var RecordType = Xrm.Page.getAttribute("nhs_recordtype").getText();

    if (RecordType == null || RecordType =='undefined' || RecordType =='')

    {

    Xrm.Page.getControl("nhs_callcentertype").clearOptions();

    }

    else if (RecordType != null && RecordType != 'undefined' && RecordType !='')

    {

    var RecordTypeText = Xrm.Page.getAttribute("nhs_recordtype").getSelectedOption().text;

    if (RecordType == "Medicare")

    {

    Xrm.Page.getControl("nhs_callcentertype").removeOption(127,130,000);

    Xrm.Page.getControl("nhs_callcentertype").removeOption(127,130,004);

    Xrm.Page.getControl("nhs_callcentertype").removeOption(127,130,005);

    }

    else if (RecordType != "Medicare")

    {

    Xrm.Page.getControl("nhs_callcentertype").addOption(127,130,000);

    Xrm.Page.getControl("nhs_callcentertype").addOption(127,130,004);

    Xrm.Page.getControl("nhs_callcentertype").addOption(127,130,005);

    }

    }

    }

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: How to show only certain items in an option set.....

    Hello,

    First - to remove use int code instead like

    Xrm.Page.getControl("nhs_callcentertype").removeOption(127130000);

    To add values - use

    Xrm.Page.getControl("nhs_callcentertype").addOption({value: 127130000, text: 'Text op optionset'});

  • USA80 Profile Picture
    26 on at
    RE: How to show only certain items in an option set.....

    Do I need  to add the actual text of the option set after the number?  So like 127130000, Football: 'Text op optionset

    ??

    Or just do what you have?

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: How to show only certain items in an option set.....

    No,

    It should be like if for optionset value with id  127130000 label is football then you can use following code

    Xrm.Page.getControl("nhs_callcentertype").addOption({value: 127130000, text: 'Football'});

  • USA80 Profile Picture
    26 on at
    RE: How to show only certain items in an option set.....

    I tried this:

    function CallCenterTypeOnChange()

    {

    var CallCenterType = Xrm.Page.getAttribute("nhs_recordtype").getText();

    if (CallCenterType == null || CallCenterType =='undefined' || CallCenterType =='')

    {

    Xrm.Page.getControl("nhs_callcentertype").clearOptions();

    }

    else if (CallCenterType != null && CallCenterType != 'undefined' && CallCenterType !='')

    {

    var RecordTypeText = Xrm.Page.getAttribute("nhs_recordtype").getSelectedOption().text;

    if (CallCenterType == "Medicare")

    {

    Xrm.Page.getControl("nhs_callcentertype").removeOption(127130000);

    Xrm.Page.getControl("nhs_callcentertype").removeOption(127130004);

    Xrm.Page.getControl("nhs_callcentertype").removeOption(127130005);

    }

    else if (CallCenterType != "Medicare")

    {

    Xrm.Page.getControl("nhs_callcentertype").addOption({value: 127,130,000, text: 'Member'});

    Xrm.Page.getControl("nhs_callcentertype").addOption({value: 127,130,004, text: 'Member & Prescriber'});

    Xrm.Page.getControl("nhs_callcentertype").addOption({value: 127,130,005, text: 'Member & Pharmacy'});

    }

    }

    }

    And received an error when I clicked on Record Type and selected Medicare 'CallCenterTypeOnChange' is undefined at eval code

  • USA80 Profile Picture
    26 on at
    RE: How to show only certain items in an option set.....

    Nevermind, found the issue, it was because I still had a , in the value.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans