Knowledge found and lost while working with Microsoft Dynamics CRM
RSS icon Home icon
  • Disabling all fields on a CRM Form

    Posted on November 21st, 2007 mitch Print Print 1 comment

    One of the feature requests that I receive quite often while creating custom CRM solutions is the have the ability to disable all or most of the fields on a CRM form based on data selected by the user.

    I've researched this off and on for quite a while but was never really able to get a solution that I was comfortable with.  Yesterday I started working on the solution in earnest and here is my solution:

     

       1: // disable all of the fields on the form.
       2: DisableFormFields = function(onOff)
       3: {
       4:     var iLen = crmForm.all.length;
       5:  
       6:     for (i = 0; i < iLen; i++)
       7:     {
       8:         o = crmForm.all[i];
       9:         switch (o.tagName)
      10:         {
      11:             case "INPUT":
      12:             case "SELECT":
      13:             case "TEXTAREA":
      14:             case "IMG":
      15:             case "IFRAME":
      16:                 if (o.id != "leadqualitycode")
      17:                 {
      18:                     o.disabled = onOff;
      19:                 }
      20:                 break
      21:             default:
      22:                 break;
      23:         }
      24:     }
      25: }

    This code needs to be placed in the form's OnLoad event.  In this example, we're working with the Lead Entity.

    The DisableFormFields() function is actually attached to the OnChange event for the Lead Status Attribute. I check the value of Lead Status and call DisableFormFields(true) to disable the fields or DisableFormFields(false) to re-enable the fields.

    Since disabling the entire form really wouldn't be a good idea, we need to allow the user to change their mind. As we loop through each of the form fields, we check the id of the field and as long as we don't encounter Lead Status, we set the fields disabled status to either true to disable the fields or false to re-enable them.

    Customization, Dynamics CRM
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    4,463 views