Disabling All Fields on a Form in CRM 2011

Wednesday, July 20, 2011

In CRM 4.0, I was very used to having to do the unsupported step of disabling fields one at a time. In CRM 2011, you can now disable the whole form at one time, which makes life much easier in case you remove fields and don’t update the form. (Not that I ever did that…)

After doing some Bing searches, I cam across this article on the Microsoft Social site. With some minor modifications, here it is to make your life easier. Winking smile

The scenario here is you have a Status Reason of On Hold in Opportunities. You don’t want users having the ability to edit On Hold Opportunities. So with this script and the Out of the Box Opportunity Entity, you can make that happen.

The cool thing is that will also NOT disable the Status Reason Field so you can undo the change!

Enjoy!

function DisableFieldOnHold()
{
   if (Xrm.Page.getAttribute("statuscode").getValue() == "2") 
   {
    disableFields();
    }
        function disableFields ()
        {
         var attributes = Xrm.Page.data.entity.attributes.get();
         for (var i in attributes)
         {
         Xrm.Page.getControl(attributes[i].getName()).setDisabled(true);
         Xrm.Page.getControl("statuscode").setDisabled(false);
         }
        }
  if (Xrm.Page.getAttribute("statuscode").getValue() != "2")
  {
  enableFields ()
  }
        function enableFields ()
        {
         var attributes = Xrm.Page.data.entity.attributes.get();
         for (var i in attributes)
         {
         Xrm.Page.getControl(attributes[i].getName()).setDisabled(false);
         }
        }
  }
Filed Under: Demo Code

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading