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:
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=====

