Search code examples
dynamics-crm-2011dynamics-crmcrmmicrosoft-dynamics

Set visible Tab or section in dynamics crm 2011


I'm a bit confused how to use that function. I'd like to hide/show tab and section by using this logic.

function setVisibleTabSection(tabname, sectionname, show) {
   var tab = Xrm.Page.ui.tabs.get(tabname);
   if (tab != null) {
      if (sectionname == null)
         tab.setVisible(show);
      else {
         var section = tab.sections.get(sectionname);
         if (section != null) {
             section.setVisible(show);
             if (show)
                tab.setVisible(show);
         }
      }
    }
 }

I didn't get how to invoke the function properly.

I created this function, also, a tab ("tab_8"), the section name is ("tab_8_section_1"), where I put the text field ("new_conf_report").

after that, I call this function (at the same place where a code was written) as setVisibleTabSection("tab_8", "tab_8_section_1", false); moreover, I call this function "onLoad" event

however I got the next errors:

 " var tab = Xrm.Page.ui.tabs.get(tabname); "'Xrm.Page.ui.tabs' - IS null or it isn't object  

  "tab.setVisible(show); " Object doesn't support this method 

thanks in advance


Solution

  • You can debug your code. Just put the word debugger in JS code. When you launch the form press F12 in tab Script press "begin script" and you are able to step by step understand how the code is working.

    If you are passing strings you have to call them like this:

    setVisibleTabSection("tab", "Sectname", false);