Disable / Enable fields, sections, tabs and the whole Form in MS CRM 2011

Disable/Enable fields, sections, tabs and the whole Form in MS CRM 2011

When working with the MS CRM form , Your requirement will be to enable (set to read/write) or disable (set to read / only) selected fields, sections, tabs and the Whole form.

Please have a glance below code for these functionalities to work out.

1)     Enable / Disable a field

Xrm.Page.getControl(“fieldname”).setDisabled(false); 

2)    Enable / Disable a Section

function sectiondisable (sectionname, disablestatus)

{

var ctrlName = Xrm.Page.ui.controls.get();

for(var i in ctrlName) {

var ctrl = ctrlName[i];

var ctrlSection = ctrl.getParent().getName();

if (ctrlSection == sectionname) {

ctrl.setDisabled(disablestatus);

}

}

}  // sectiondisable

3)    Enable / Disable a Tab

function tabdisable (tabname, disablestatus)
{
 var tab = Xrm.Page.ui.tabs.get(tabname);
 if (tab == null) alert("Error: The tab: " + tabname + " is not on the form");
 else {
     var tabsections =  tab.sections.get();
     for (var i in tabsections) {
         var secname = tabsections[i].getName();
         sectiondisable(secname, disablestatus);
     }
  }
}   // tabdisable

 

4)    Enable / Disable a Form

function formdisable(disablestatus)
{
    var allAttributes = Xrm.Page.data.entity.attributes.get();
    for (var i in allAttributes) {
           var myattribute = Xrm.Page.data.entity.attributes.get(allAttributes[i].getName());
           var myname = myattribute.getName();          
           Xrm.Page.getControl(myname).setDisabled(disablestatus); 
    }
} // formdisable

5)     Enable / Disable All Controls in the TAB

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 EnableAllControlsInTab(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(false);  
        }  
    });  
    } 
 }

 Hope this will help.

Regards,

Advertisements

One thought on “Disable / Enable fields, sections, tabs and the whole Form in MS CRM 2011

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s