Monday 21 May 2012

MS CRM 2011 JavaScript common UI (User Interface) functions

I am listing some common MS CRM 2011 JavaScript UI functions.These functions are for the MS CRM 2011 User Interface.

1.Hiding a navigation Item:
 ShowOrHideNavigationItem("navContacts",false)
//====== Function to Hide navigation Item Start====== 
function ShowOrHideNavigationItem(NavItemName, ShowOrHide) 
{
    var navItem = Xrm.Page.ui.navigation.items.get(NavItemName);
    if (navItem != null)
        navItem.setVisible(ShowOrHide);
}
//====== Function to Hide navigation Item End======== 
2.Show or Hide a Control :
 ShowOrHideControl("myControlName",false)




//====== Function to Show or Hide a Control Start====== 
function ShowOrHideControl(CtrlItemName, ShowOrHide)
{
    var ctrlItem = Xrm.Page.getControl(CtrlItemName);
    if (ctrlItem != null)
        ctrlItem.setVisible(ShowOrHide);
}
//====== Function to Show or Hide Control End========
3.Enable or Disable a Control :
EnableOrDisableControl("myControlName",true)
//====== Function to Enable or Disable a Control Start====== 
function EnableOrDisableControl(CtrlItemName, EnableOrDisable)
{
    var ctrlItem = Xrm.Page.getControl(CtrlItemName);
    if (ctrlItem != null)
        ctrlItem.setDisabled(EnableOrDisable);
}
//====== Function to Enable or Disable a Control End======
4.Set a Control Required Level:
SetControlRequiredLevel("myControlName",required)
//====== Function to Set Required Level a Control Start====
function SetControlRequiredLevel(CtrlItemName, RequiredLevel)
{
    //RequiredLevel="required","none"
    var ctrlItem = Xrm.Page.getControl(CtrlItemName);
    if (ctrlItem != null)
        ctrlItem.setRequiredLevel(RequiredLevel);
}
//====== Function to Set Required Level a Control End======
5.Hide or Show a Section:
HideShowSection(1, mySectionName, false)
//====== Function to Show and Hide a section Start====== 
function HideShowSection(tabnumber, section, visible)
{
    if (Xrm.Page.ui.tabs.get(tabnumber) != null && Xrm.Page.ui.tabs.get(tabnumber).sections.get(section) != null)
        Xrm.Page.ui.tabs.get(tabnumber).sections.get(section).setVisible(visible);
}




//====== Function to Show and Hide a section End====== 
6.Hide or Show a Tab:
HideShowTab(1,false)
//====== Function to  Show and Hide a Tab Start====== 
function HideShowTab(tabnumber, visible)
{
    Xrm.Page.ui.tabs.get(tabnumber).setVisible(visible);
}
//====== Function to Show and Hide a Tab End====== 
7.Disable all the controls in a Tab:




DisableAllControlsInTab(1)
//====== Function to Disable all Controls in a Tab Start=====
function DisableAllControlsInTab(tabControlNo)
{
    var tabControl = Xrm.Page.ui.tabs.get(tabControlNo);
    if (tabControl != null) {
        Xrm.Page.ui.controls.forEach(
    function (control, index) {
        if (control.getParent().getParent() == tabControl && control.getControlType() != "subgrid") {
            control.setDisabled(true);
        }
    });
    }
}
//====== Function to Disable all Controls in a Tab End=====
8.Disable all the controls in a Section:




DisableOrEnableAllControlsInSection("sectionName",true)
//====== Function to Disable or all Controls in a Section Start=====
function DisableOrEnableAllControlsInSection(sectionControl, DisableOrEnable) 
{




    Xrm.Page.ui.controls.forEach(
    function (control, index) {
        if (control.getParent().getName() == sectionControl) {
            control.setDisabled(DisableOrEnable);
        }
    });
}
//====== Function to Disable or all Controls in a Section End=====
9.Disable the form:
//====== Function to Disable form Start=====
function DisableForm() 
{
    Xrm.Page.ui.controls.forEach(
        function (control, index) {
            if (control.getControlType() != "subgrid")
                control.setDisabled(true);
        });
}
  //====== Function to Disable form End=====

1 comment:

  1. Any thoughts on how to hide the entire left nav pane? In Design mode, the setting is under Form Properties / Display. I need to leave it enabled by default and I want to let the user selectively choose (via maybe a Ribbon button) to toggle displaying the left nav area. I need to maximize screen real estate so I want to give users with small laptops the freedom to hide the entire left side nav pane. We can easily toggle showing the huge Ribbon buttons, but not the left nav pane (argh!).

    ReplyDelete