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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Show/Hide Sections based on drop down value

(0) ShareShare
ReportReport
Posted on by

I'm relatively new to CRM and need help in setting up my CRM form to Show/Hide a section based on a value from a drop down.  Note:  Each value from the drop down will have it's own dedicated section, therefore it will be important to show only one particular Section while hiding of the others.  (see illustration)

 

I assume that I will need to use javascrip to do this since a basic Business Rule doesn't allow you to choose a section to control its visibility.  Since I'm new at this, can someone please take the time to give me detailed instructions on how to set this up?  I appreciate your help with this.

Thanks,

Doug

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at

    Hi..

    You need to write JavaScript on DropDown on change and Form Onload.

    To show/ hide section use code like

    var tab=Xrm.Page.ui.tabs.get(TabName);
    var section = tab.sections.get(SectionName);
    section.setVisible(true); // To show section

    section.setVisible(false); // To Hide section


    To Get Tab name-

    Select tab in form customization, and click on Change Properties.

    You can change Tab Name from above screen and give some realistic name instead of GUID.

    Same way you can get section name, and default CRM will give GUID for section name.. your some realistic name of section also. 

    Hope this will help.. 

  • Suggested answer
    Royal King Profile Picture
    27,686 on at

    check the below post that will walk you through steps to show/hide section in the system

    community.dynamics.com/.../hiding-a-section-and-fields-in-microsoft-dynamics-crm-2013-using-business-rules.aspx

  • Community Member Profile Picture
    on at

    I appreciate your feedback but I don't see in your example where you are triggering the visibility from the value from a drop down field (see my illustration).  NOTE:  I do NOT have any fields in the section that I'm trying to show/hide.  I only have a grid in that section therefore, a simple business rule can't show/hide the grid.  That is why I need to show/hide the Section based on a value from a dropdown.  I appreciate your help with this.

  • Suggested answer
    Royal King Profile Picture
    27,686 on at

    Add the below script in your web resource and call showHide in onload of the form.

    Make sure to replace all field names and tab and sectionnames in the script

    function showHide()

    {

    Xrm.Page.getAttribute("optionsetfieldname").addOnChange(function(){

    if(Xrm.Page.getAttribute("optionsetfieldname").getValue())

    Xrm.Page.ui.tabs.get("tabname").sections.get("sectionname").setVisible(true);

    else

    Xrm.Page.ui.tabs.get("tabname").sections.get("sectionname").setVisible(false);

    });

    }

  • Community Member Profile Picture
    on at

    Chitra:

    Thank you for your help with this.  Can you please help me understand how I determine what my "optionsetfieldname" is?  Is this my different drop down option values (Example: Option 1, Option 2 ... )

    If so, I'm guessing that I will need a line for each option.  Will I need to create a seperate line for each "hide" as well?

    Thanks,

    Doug

  • Royal King Profile Picture
    27,686 on at

    say if your dropdown field name is "new_department" and it has values

    1-  Account - Show section with name "account"

    2-  Sales - Show section with name "Sales"

    3 - Marketing - Show section with name "Marketing"

    function showHide()

    {

    Xrm.Page.getAttribute("optionsetfieldname").addOnChange(function(){

    var selectedDeaprtment =Xrm.Page.getAttribute("optionsetfieldname").getValue();

    if(selectedDeaprtment  == 1)

    Xrm.Page.ui.tabs.get("tabname").sections.get("account").setVisible(true);

    else if(selectedDeaprtment  == 2)

    Xrm.Page.ui.tabs.get("tabname").sections.get("sectionname").setVisible(true);

    });

    }

  • Suggested answer
    Community Member Profile Picture
    on at

    Try this.

    technet.microsoft.com/.../dn531086.aspx

  • Community Member Profile Picture
    on at

    Chitra - Can I please get clarification?  Does your "1" in your code if(selectedDeaprtment == 1) represent the Label or the Value of the choice?

  • Royal King Profile Picture
    27,686 on at

    value of the choice

  • Community Member Profile Picture
    on at

    Great!  That's what I've got in the code.  However, nothing is showing when I use the dropdown.  I must be missing something.  Here is my code:

    function showHide()

    {

    Xrm.Page.getAttribute("optionsetfieldname").addOnChange(function(){

    var selectedwiretie_nationalaccounts_list =Xrm.Page.getAttribute("optionsetfieldname").getValue();

        if(selectedwiretie_nationalaccounts_list  == 100,000,000)

        Xrm.Page.ui.tabs.get("National Accounts").sections.get("Caraustar_Grid").setVisible(true);

        else if(selectedwiretie_nationalaccounts_list  == 100,000,001)

        Xrm.Page.ui.tabs.get("National Accounts").sections.get("CommercialMetals_Grid").setVisible(true);

        else if(selectedwiretie_nationalaccounts_list  == 100,000,002)

        Xrm.Page.ui.tabs.get("National Accounts").sections.get("GeorgiaPacific_Grid").setVisible(true);

        else if(selectedwiretie_nationalaccounts_list  == 100,000,003)

        Xrm.Page.ui.tabs.get("National Accounts").sections.get("ProgressiveWaste_Grid").setVisible(true);

        else if(selectedwiretie_nationalaccounts_list  == 100,000,004)

        Xrm.Page.ui.tabs.get("National Accounts").sections.get("ReCommunity_Grid").setVisible(true);

        else if(selectedwiretie_nationalaccounts_list  == 100,000,005)

        Xrm.Page.ui.tabs.get("National Accounts").sections.get("Republic_Grid").setVisible(true);

        else if(selectedwiretie_nationalaccounts_list  == 100,000,006)

        Xrm.Page.ui.tabs.get("National Accounts").sections.get("RockTenn_Grid").setVisible(true);

        else if(selectedwiretie_nationalaccounts_list  == 100,000,007)

        Xrm.Page.ui.tabs.get("National Accounts").sections.get("ShredIt_Grid").setVisible(true);

        else if(selectedwiretie_nationalaccounts_list  == 100,000,008)

        Xrm.Page.ui.tabs.get("National Accounts").sections.get("Sonoco_Grid").setVisible(true);

        else if(selectedwiretie_nationalaccounts_list  == 100,000,009)

        Xrm.Page.ui.tabs.get("National Accounts").sections.get("WasteManagement_Grid").setVisible(true);

    else

    Xrm.Page.ui.tabs.get("National Accounts").sections.get("NationalAccountGrids").setVisible(false);

    });

    }

    Am I missing anything here?

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans