Disable / enable fields, sections, tabs and the whole form in CRM 2011

When working with CRM, you often want to enable (set to read/write) or disable (set to read / only) selected fields, sections, tabs and the whole form depending on your business logic. This is can be derived from studying the SDK and creating som code, but here are my easy-to-use support functions to complement the base functions.

1) Enable / Disable a field

Xrm.Page.getControl("fieldname").setDisabled(false);  // true = R/W, false = R/O

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) {
}  // 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();          
} // formdisable

About Eirik

I have worked with Microsoft CRM since 2007, mainly with the design of business logic and system configuration. For me as a system owner, I find the product exciting to work with: I can rapidly build business logic, new entities and workflows based upon rapidly changing needs from our business. I have also found back to some of my old programming roots by doing quite a bit of Javascript!. When it comes to the building of more heavy duty integration components and plugins I leave that work to my more technically clever colleges. In EDB ErgoGroup I am from Jan 1, 2011 VP of Customer Relationship Development. This includes areas such as product marketing, customer development and being responsible for the corporate CRM solutions. These are today mainly based on Microsoft CRM. We will during 2011 transform and fuse existing CRM tools into one new solution built upon Microsoft Dynamics CRM 2011. This is an exciting project - and I will share some of our experiences in this blog.
This entry was posted in CRM 2011, Javascript. Bookmark the permalink.

2 Responses to Disable / enable fields, sections, tabs and the whole form in CRM 2011

  1. Edwin says:

    function tabdisable (tabname, disablestatus)

    in the above code do i fill in the tabname, and disable status with real values e.g “General”, false?

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>