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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Based on Option Set Hide and Show to Section

(0) ShareShare
ReportReport
Posted on by 1,432

Hi all 

how to Hide and show Section Based On OptionSet 

In My Tab I have 3 Section  Based On OptionSet Value i Need to Show and Hide Section Please Give Some Suggestions ???

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Surmeet Singh Profile Picture
    3,075 on at

    HI KNK,

    You can do that

    in the following way by calling this function onload of Form and onChange of Optionset field

    function ShowHideSectionsBySubject() {

       var tabName = "tab_Name";

       var sectionPicklistValue = Xrm.Page.data.entity.attributes.get("optionset_field").getValue();

    if(sectionPicklistValue == 1)

    {

    Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex1).setVisible(false);

    Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex2).setVisible(true);

    Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex3).setVisible(true);

    }

    else if(sectionPicklistValue == 2)

    {

    Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex2).setVisible(false);

    Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex1).setVisible(true);

    Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex3).setVisible(true);

    }

    else if(sectionPicklistValue == 3)

    {

    Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex3).setVisible(false);

    Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex1).setVisible(true);

    Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex2).setVisible(true);

    }

    }

  • l ringel Profile Picture
    on at

    Hi there,

    I'm trying to something very similar. I have two sections on a form, both in the same Tab. I want them to hid based off the value of an option set field. I added this script onChange of the field I want it base it off, but doesn't work.

    Thank You

    Leibish Ringel

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi,

    There are two ways to hide sections based on option set value.

    1. Using Business Rules: Hiding all the fields contained in a section automatically hides the section. This can be used especially when you have few fields in your section.

    2. Using Javascript: You can also show/hide a section using this JS code:

    Xrm.Page.ui.tabs.get("tabname").sections.get("sectioname").setVisible(true);  //Shows a section
    
    Xrm.Page.ui.tabs.get("tabname").sections.get("sectioname").setVisible(false);  //Hides a section

    Register the below function on-load event of the form as well as the on-change event of the option set field and hide and show sections as required.

    function HideOrShowSectionBasedOnoptionSetValue(){
     var value = Xrm.Page.getAttribute("optionSetFieldName").getValue();
     if(value!=null){
      if(value == 1){
        Xrm.Page.ui.tabs.get("tabname").sections.get("section1Name").setVisible(true);  //Shows section 1
        Xrm.Page.ui.tabs.get("tabname").sections.get("section2Name").setVisible(false);  //Hides section 2
        Xrm.Page.ui.tabs.get("tabname").sections.get("section3Name").setVisible(false);  //Hides section 3
    } 
      else if(value == 2){ 
        Xrm.Page.ui.tabs.get("tabname").sections.get("section1Name").setVisible(false);  //Hides section 1
        Xrm.Page.ui.tabs.get("tabname").sections.get("section2Name").setVisible(true);  //Shows section 2
        Xrm.Page.ui.tabs.get("tabname").sections.get("section3Name").setVisible(false);  //Hides section 3
     } 
      else if(value ==3){ 
        Xrm.Page.ui.tabs.get("tabname").sections.get("section1Name").setVisible(false);  //Hides section 1
        Xrm.Page.ui.tabs.get("tabname").sections.get("section2Name").setVisible(false);  //Hides section 2
        Xrm.Page.ui.tabs.get("tabname").sections.get("section3Name").setVisible(true);  //Showssection 3
      }
     } 
    } 

    Hope this helps.

  • l ringel Profile Picture
    on at

    Hi Nithya,

    Thank you for your reply.

    When I register the function do I add anything to the parameter list?

  • Sravan Kumar Chandhavolu Profile Picture
    140 on at

    Not needed. What Nithya replied is pitch perfect and needs no more edits.

    Regards,

    Sravan.

  • l ringel Profile Picture
    on at

    Hi Sravan,

    I copied the exact script and added my corresponding fields, tab and sections name to the script

    function HideOrShowSectionBasedOnoptionSetValue(){

    var value = Xrm.Page.getAttribute("msdyn_ordertype").getValue();

    if(value!=null){

     if(value == 1){

       Xrm.Page.ui.tabs.get("Summary").sections.get("Insurance_Information").setVisible(true);

       Xrm.Page.ui.tabs.get("Summary").sections.get("Secondary_Insurance").setVisible(true);

    }

     else if(value == 2){

       Xrm.Page.ui.tabs.get("Summary").sections.get("Insurance_Information").setVisible(false);

       Xrm.Page.ui.tabs.get("Summary").sections.get("Secondary_Insurance").setVisible(false);

    }

    }

    }

    and go this error,

    Script Error

    One of the scripts for this record has caused an error. For more details, download the log file.

    TypeError: Cannot read property 'setVisible' of null at HideOrShowSectionBasedOnoptionSetValue

    Is there something I still need to do or am I doing this wrong?

    Thank You

    Leibish Ringel

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Lebish,

    Please ensure that the names of sections and tabs are the same as they appear in the Tab and Section Properties.

    In order to get these names, Select the Tab or Section in the Form Editor and click on Change Properties in the command bar.

    The names of tab and section are highlighted in the screenshots below.

    1067.2.PNG      1067.2.PNG

    Hope this helps.

  • Suggested answer
    Community Member Profile Picture
    on at
  • FidelMartin Profile Picture
    128 on at
    With Conditioned based triggers, you can choose to show/hide tabs in Dynamics.
     

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

News and Announcements

Season of Giving Solutions is Here!

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
Shidin Haridas Profile Picture

Shidin Haridas 2

#2
Abdullah13 Profile Picture

Abdullah13 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans