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 is a developer and architect focusing on Microsoft Dynamics 365, BI, Web, Cloud and Data Science.

carldesouza.comLinkedIn Twitter | YouTube


2 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!!

Leave a Reply

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