Home › Dynamics 365 Customer Engagement (CRM) › Dynamics CRM Read Only Form and Disable Fields with JavaScript
Dynamics 365 Customer Engagement (CRM) · Jun 17, 2016 · 1 MIN READ

Dynamics CRM Read Only Form and Disable Fields with JavaScript

One way to lock down a form is through JavaScript. Let’s go through how to do this by locking down the Leads form.

Create a new solution and add the Leads form:

Select Form Properties and Add from the Form Library. We will be adding a new JavaScript library:

Select New:

Enter information below:

Click Text Editor and enter the JavaScript:

function ReadOnly ()
{
 var cs = Xrm.Page.ui.controls.get();
 for (var i in cs) 
 {
  var c = cs[i];
  if (c.getName() != "" && c.getName() != null) 
  {
   if (!c.getDisabled()) {c.setDisabled(true);}
  }
 }
}

Press Save and Publish.

Select Add:

On the Form Properties page, click Add under Event Handlers. Select the new library and for the function type ReadOnly:

Click OK, Save and Publish the form. The function is now ready to use.

Go to a Leads record. All fields will be disabled:

 

 

Carl de Souza
Keep learning. Keep building.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.

Subscribe on YouTube →
Carl de Souza Enterprise Architect at Microsoft · AI Technology Expert

5 Responses to Dynamics CRM Read Only Form and Disable Fields with JavaScript

  1. This is great except your line: if (!c.getDisabled()) {c.setDisabled(true); is missing the closing bracket which is why it didn’t work for me and I got a JavaScript error. Once that was changed, it worked! Thanks a ton!!

  2. How to ignore quick view control?
    There is a lock symbol showing up in front of quick view control as well. I don’t want it to lock quick view control which is non editable by default.

Leave a Reply

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

Carl de Souza
KEEP LEARNING. KEEP BUILDING.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.