CRM Software Logo

A panel of Microsoft Dynamics CRM experts provide reviews and opinions to aid professionals with the CRM selection process.

 
 
McGladrey LLP

Microsoft Dynamics CRM Ease of Use Demonstrated with Changing a Form to Read-Only Based on a Field Value: Part I

Email | Print

Microsoft Dynamics CRM is a solution that is flexible, scalable and easy to use.  In some cases, that may mean changing how a field value behaves in the system.  The Microsoft Dynamics CRM platform allows organizations to change the system according to their needs.

In the example below, I will explain how to make a form read-only based on a field value:

With Microsoft Dynamics CRM 2011, there are several methods that can be used to restrict users’ abilities to modify a record.  The simplest method is to remove the “Write” access for that entity in the users’ security role.  But what if you only want to restrict the ability to modify a record based on a field value?  This is possible by adding some Javascript.

Below I outline how an existing Account record (form type 2) is changed to read-only if the Account Status = “Customer” (new_accountstatus option set value 100,000,001).  In basic terms, you'd create a new Web Resource library with this Javascript (changing the field name and value as applicable for your use), add the library to the Account entity, and set the Event Handler to run the setupForm function OnLoad.

function setupForm()

{
  if (Xrm.Page.ui.getFormType() == 2 && Xrm.Page.getAttribute("new_accountstatus").getValue() == 100000001)
   {
    disableFormFields(true);
   }
}

function doesControlHaveAttribute(control)

{
    var controlType = control.getControlType();
    return controlType != "iframe" && controlType != "webresource" && controlType != "subgrid";
}

function disableFormFields(onOff)

{
  Xrm.Page.ui.controls.forEach(function (control, index)
   {
     if (doesControlHaveAttribute(control))
      {
         control.setDisabled(onOff);
       }
    });
}

Step-by-step instructions for adding the Javascript:

  1.  Navigate to the Customizations screen (Settings > Customizations > Customize the System).
  2. Select the Web Resources link, and click on New.  In the new Web Resource window, enter a Name (with no spaces) and a Display Name.  Select “Script (Jscript)” for the Type, and click on Text Editor.
  3. Paste the Javascript into the text window, and click on OK.
  4. Save and Close the Web Resource window.
  5. Back on the Customizations window, expand the Entities link, then expand Account, and click on Forms.  Open the form to which you want to apply the Javascript function.
  6. With the Account Form open, click on Form Properties
  7. In the Form Properties window, click on Add in the Form Libraries section.  A Look Up window will open.  Select your new library, and click on OK.
  8. In the Event Handler section of the Form Properties window, set the Control = Form, and Event = OnLoad, then click on the Add button.  In the Handler Properties window select your new Library, and type setupForm in the Function field.  Make sure the Enabled box is checked, and click on OK.
  9. After adding the library and event handler, click on OK to save and close the Form Properties window.
  10. Back on the Account Form, click on Save, and then Publish.
  11. When an existing Account record is opened, if the Account Status field is blank or set to anything other than “Customer”, the fields can be modified:
  12. But if the Account Status is set to “Customer”, the fields become read-only:

    NOTE: even though the fields on the Account form are read-only, iFrames and sub grids embedded in the record, such as the Contacts sub grid, can still be modified:

Coming up in Part 2 of my blog, I’ll demonstrate how this Javascript can be changed to allow some fields on your read-only form to be modified.

There are a number of other ways the system can be configured to fit the needs of your business.  McGladrey is a partner with the Gold Customer Relationship Management (CRM) Competency in the Microsoft Partner Network and can implement Microsoft Dynamics CRM solutions from the basic "out of the box" model to a complex architecture. This competency means McGladrey demonstrates an ability to meet Microsoft customers’ evolving needs in today’s dynamic business environment and has completed a rigorous set of tests to prove their level of technology expertise.

If you are interested in learning more about how McGladrey can help your organization, our professionals can be reached via email at [email protected] or by phone at 800.274.3987.

By: Melissa Otto, McGladrey – Microsoft Dynamics CRM Partner in New Jersey and Minnesota

 

Ask This Expert a Question / Leave a Comment