Disabling all fields in CRM 2013

Hi,

We were using the below function in CRM 2011 for disabling all the fields in the form.

function makeAllAttributesReadOnly() {

var attributes = Xrm.Page.data.entity.attributes.get();

for (var i in attributes) {
var myattribute = Xrm.Page.data.entity.attributes.get(attributes[i].getName());
var myname = myattribute.getName();
Xrm.Page.getControl(myname).setDisabled(true);
}
}

However this function in CRM 2013 was giving us setDisabled field is undefined JavaScript error.

As it turned out it was because of the StateCode (Status) field in CRM 2013.

Modifying the above code to leave this particular field resolved the issue.

function makeAllAttributesReadOnly() {
var attributes = Xrm.Page.data.entity.attributes.get();
for (var i in attributes) {

var myattribute = Xrm.Page.data.entity.attributes.get(attributes[i].getName());
var myname = myattribute.getName();
if(myname == "statecode")
{
return;
}
Xrm.Page.getControl(myname).setDisabled(true);
}
}

Hope it helps.


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

One thought on “Disabling all fields in CRM 2013”

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s