Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Show/Hide optionset values....

Posted on by 2,645

Hello,

Here is my scenario:

I have Field A that is a drop down, Field B is a lookup and Field C is a drop down.  Some how I need that when Field A is Football and Field B is Stadium and Field C is Yes, that then Field D shows only certain items in the optionset list..

function SportTypeOnChange()
 {
 var Sport = Xrm.Page.getAttribute("nhs_Sport").getText();
 var Place = Xrm.Page.getAttribute("nhs_place").getText();
 var Startup = Xrm.Page.getAttribute("nhs_startup").getText();
 
  if (Sport == null || Sport =='undefined' || Sport =='')
   {
    Xrm.Page.getControl("nhs_callcentertype").clearOptions();
   }
  else if (Sport != null && Sport != 'undefined' && Sport !='')
   {
   var SportText = Xrm.Page.getAttribute("nhs_Sport").getSelectedOption().text;
   var PlaceText = Xrm.Page.getAttribute("nhs_place").getSelectedOption().text;
   var StartupText = Xrm.Page.getAttribute("nhs_startup").getSelectedOption().text;
   
    if (Sport == "Football" && Place == "Stadium" && Startup == "No")
     {
      Xrm.Page.getControl("nhs_callcentertype").removeOption(127130000);
      Xrm.Page.getControl("nhs_callcentertype").removeOption(127130004);
      Xrm.Page.getControl("nhs_callcentertype").removeOption(127130005);
     }
  else if (Sport == "Football" && Place == "Stadium" && Startup == "Yes")
     {
      Xrm.Page.getControl("nhs_callcentertype").addOption({value: 127130000, text: 'NFL'});
      Xrm.Page.getControl("nhs_callcentertype").addOption({value: 127130001, text: 'Soccer'});
      Xrm.Page.getControl("nhs_callcentertype").addOption({value: 127130002, text: 'Golf'});
      Xrm.Page.getControl("nhs_callcentertype").addOption({value: 127130003, text: 'NHL'});
      Xrm.Page.getControl("nhs_callcentertype").addOption({value: 127130004, text: 'NBA'});
     }
   }
 }

Can this be done, if so how?  I am getting an getText error

*This post is locked for comments

  • Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: Show/Hide optionset values....
    with a lookup my solution will not work,you need to debug your code (and start to write the field names as all lowercase)
  • USA80 Profile Picture
    USA80 2,645 on at
    RE: Show/Hide optionset values....

    Would this actually work with a lookup field as part of the condition?  My first field needs to be Football, then the other 2 fields, one is a lookup field and the other is an option set field.  The field that is a drop down will always show the same values so this list isn't dependent on any field.  Only the 4th field is dependent on the other 3 fields for what their values are.  Hope that make sense

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: Show/Hide optionset values....

    you can use my Dependent Optionset Generator solution

    http://crmoptionsets.azurewebsites.net/

    check the demo

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans