Wednesday 14 August 2013

Showing only selected Tab on the MS CRM 2011 Form

When you open any form it loads all the tabs on the form.Suppose you want to display the selected tab on the form at a time.Here is a JavaScript function to hide the other tabs.This function can be called on the Form OnLoad and TabStateChange events.

1.JavaScript Function:

function ToggleTabDisplayState(name) {
 
    var currentTab = Xrm.Page.ui.tabs.get(name);
    if (currentTab != null && currentTab.getDisplayState() == "expanded") {
        var currentTabId = currentTab._control.get_id();
        var tabs = Xrm.Page.ui.tabs.get();
        for (var i in tabs) {
            var tab = tabs[i];
            var tabId = tab._control.get_id();
            if (tabId != currentTabId) {
                if (tab.getDisplayState() == "expanded") {
                    tab.setDisplayState("collapsed");
                }
                document.getElementById(tabId).style.display = "none";
            }
        }
    }
}
2.Before Calling the Function :
Form shows all the tabs before calling the above function Form OnLoad event.
 
 
 
 3.Calling the Function :
 
3.1 Call on Form OnLoad event :
 
Suppose on Form OnLoad event I want to show only "General" tab and hide other tabs then call the above function as below.
 
function Form_OnLoad() {
    ToggleTabDisplayState("general"); //"general" is the name of the tab
}
 
3.2 Call on TabStateChange event:
 
Call the same function on the TabStateChange event 
 
Go to Form Properties =>Select Control as tab name=>Add Handler =>Select Library=>add function as ToggleTabDisplayState =>Provide name of the tab in Comma separated parameters list for example 
"contacts" => Save and publish


4.After Calling the Function :
Form shows only selected tab after calling the above function Form OnLoad event.
 
 










Hope it helps,
Regards,
Yusuf



No comments:

Post a Comment