Thursday, 6 October 2011

Adding Tabs in CRM 2011 Forms like CRM 4.0 Forms

Sometimes, the users are so used to with the tabs from CRM 4.0 forms that they are not happy with the tab sections from CRM 2011 forms. And sometimes, the input data from one tab has to be populated in another tab according to the workflow of the business process.
In such situations, we've got no choice but to simulate the tabs of CRM 4.0 form by embedding an HTML web resource with tab controls in the header of the form which will show/hide the tab sections upon clicking.

To start implementing, download the HTML file from here.
Upload that HTML file as a web resource in your CRM organization solution.
Open the form that you want to add tabs and insert the uploaded web resource in the header of that form.
Go to the Formatting tab and change the number of rows to 1 and occupy all columns in layout.

Save the form and publish.
So, the final result of the form will be as shown in the screenshot below.

PS: Currently, I've just added 12 tabs in the html web resource so that it can handle the forms with maximum 12 tabs. If your form has more than 12 tabs, you have to edit the HTML file and add more tab items (li nodes) and re-upload the html web resource.

For those who are not able to download the html file from the Google Drive link above, check out the source code in the box below.

 <head id="Head1" runat="server">  
           function tabOnLoad()  
                var tabHeight = document.getElementById("crmTabBar").offsetHeight + 2;  
                parent.document.getElementById("crmFormHeader").parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.height = parent.document.getElementById("crmFormHeader").parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.offsetHeight - 17;  
           function LoadTabs()  
                var crmTabBar = document.getElementById("crmTabBar");  
                var tabCollection = parent.Xrm.Page.ui.tabs;  
                for(i = 0; i < tabCollection.getLength() & i <= crmTabBar.children.length; i++)  
                          var tabID = tabCollection.get(i).getName();  
                          var NewTabItem = crmTabBar.children[i];  
                 = tabID + "Tab";  
                          NewTabItem.tabID = tabID;  
                          NewTabItem.onclick = function() { SelectTab(, - 3));};  
                          //var NewDiv = document.createElement("div");  
                          // = tabID;  
                          // = 'hidden';  
                          var AnchorItem = NewTabItem.children[0];  
                          AnchorItem.innerText = tabCollection.get(i).getLabel();  
                for(i = crmTabBar.children.length - 1; i >= tabCollection.getLength(); i--)  
           function HideAllTabs(shownTab)  
                var isAllHidden = false;  
                var count = 0  
                while(!isAllHidden && count <5)  
                     isAllHidden = true;  
                     for(i = 0; i < parent.Xrm.Page.ui.tabs.getLength(); i++)  
                          if(parent.Xrm.Page.ui.tabs.get(i).getVisible() && parent.Xrm.Page.ui.tabs.get(i).getName() != shownTab)  
                               isAllHidden = false;  
           function SelectTab(tabName)  
                     parent.window[tabName.replace(/\s/g,"_") + "Tab_GotFocus"]();  
 <script type="text/javascript" src="/_common/global.ashx"></script>  
 <link rel="stylesheet" type="text/css" href="/_common/styles/fonts.css.aspx" />  
 <link rel="stylesheet" type="text/css" href="/_common/styles/global.css.aspx" />  
 <link rel="stylesheet" type="text/css" href="/_common/styles/theme.css.aspx" />  
 <link rel="stylesheet" type="text/css" href="/_forms/controls/controls.css.aspx" />  
 <link rel="stylesheet" type="text/css" href="/_common/styles/select.css.aspx" />  
 <link rel="stylesheet" type="text/css" href="/_common/styles/miniCal.css.aspx" />  
 <link rel="stylesheet" type="text/css" href="/_nav/menu.css.aspx" />  
 <link rel="stylesheet" type="text/css" href="/_forms/controls/notifications/notifications.css.aspx" />  
 <link rel="stylesheet" type="text/css" href="/_forms/controls/form.css.aspx" />  
 <link rel="stylesheet" type="text/css" href="/_common/styles/dialogs.css.aspx" />  
 <link rel="stylesheet" type="text/css" href="/_nav/tabs.css.aspx" />  
 <link rel="stylesheet" type="text/css" href="/_grid/appgrid.css.aspx" />  
 <link rel="stylesheet" type="text/css" href="/_controls/lookup/lookupdialogs.css.aspx" />  
 <body onload="tabOnLoad()">  
 <table cellSpacing=0 cellPadding=0 width="100%" height="100%"><tbody>  
 <td class=ms-crm-TabBar-Cell>  
 <ul style="width: 565px" id=crmTabBar class=ms-crm-TabBar valign="bottom" nowrap>  
 <li id="tab1" class="ms-crm-Tab" tabIndex=-1 tabID="tabID1"><a href="#" target=_self>zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz</a></li>  
 <li id="tab2" class="ms-crm-Tab" tabIndex=-1 tabID="tabID2"><a href="#" target=_self>zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz</a></li>  
 <li id="tab3" class="ms-crm-Tab" tabIndex=-1 tabID="tabID3"><a href="#" target=_self>zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz</a></li>  
 <li id="tab4" class="ms-crm-Tab" tabIndex=-1 tabID="tabID4"><a href="#" target=_self>zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz</a></li>  
 <li id="tab5" class="ms-crm-Tab" tabIndex=-1 tabID="tabID5"><a href="#" target=_self>zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz</a></li>  
 <li id="tab6" class="ms-crm-Tab" tabIndex=-1 tabID="tabID6"><a href="#" target=_self>zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz</a></li>  
 <li id="tab7" class="ms-crm-Tab" tabIndex=-1 tabID="tabID7"><a href="#" target=_self>zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz</a></li>  
 <li id="tab8" class="ms-crm-Tab" tabIndex=-1 tabID="tabID8"><a href="#" target=_self>zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz</a></li>  
 <li id="tab9" class="ms-crm-Tab" tabIndex=-1 tabID="tabID9"><a href="#" target=_self>zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz</a></li>  
 <li id="tab10" class="ms-crm-Tab" tabIndex=-1 tabID="tabID10"><a href="#" target=_self>zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz</a></li>  
 <li id="tab11" class="ms-crm-Tab" tabIndex=-1 tabID="tabID11"><a href="#" target=_self>zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz</a></li>  
 <li id="tab12" class="ms-crm-Tab" tabIndex=-1 tabID="tabID12"><a href="#" target=_self>zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz</a></li>  
 <div style="visibility:hidden" id="tabID1">  


  1. We have been using your horizontal tab solution but it stops working in rollup 12, I guess because of the cross browser support. Would it make any difference if we implement the Microsoft solution to limit browser support to Internet Explorer in rollup 12 and beyond?

    1. Pls download the latest version and try it again. At least it should work on IE and Chrome. I'll try to make it working in other browsers as well.

      The decision about the CRM system to limit to IE only for UR 12 and beyond is up to the clients and their demands. One good thing about limiting to IE only is that such unsupported client scripting like accessing DOM (as in this tab solution) will most likely be working even after latest rollups. If we let the clients use all supported browsers, the client scripting will be limited to supported methods only.

      For more information, you can read about that in the following MSDN link.

    2. We really appreciate your response on this. I downloaded the latest version and got it working in rollup 12, once I had set System Settings / Customisation as follows, HTC compatibility = on, Latest Internet Compatibility = off
      Many thanks for your help.

  2. I am interested in downloading the HTML page above, but the link does not work for me (seems broken). Could you perhaps make it available somehow? Thanks!

    1. I've tried downloading from the link and it's still working.
      Anyway, I've updated the post to include the source code. Hope it helps.

  3. Does this work with CRM Dynamics 2015

  4. Great, Thanks!

    Make it work with Dynamics 365, but there are some css difficulties.
    Active tab is not highlighted, for example.