CRM 2011 Training Series – How to disable all fields on the form through Jscript?


How to disable all fields on the form through Jscript?

There are many occasions where you need to disable all fields/controls on an entity form. Here is the code snippet that shows how to do that.

// JScript source code
function DisableFieldOnHold() {
if (Xrm.Page.getAttribute(“statuscode”).getValue() == “2”) {
disableFields();
}
function disableFields() {
var attributes = Xrm.Page.data.entity.attributes.get();
for (var i in attributes) {
Xrm.Page.getControl(attributes[i].getName()).setDisabled(true);
Xrm.Page.getControl(“statuscode”).setDisabled(false);
}
}
if (Xrm.Page.getAttribute(“statuscode”).getValue() != “2”) {
enableFields()
}
function enableFields() {
var attributes = Xrm.Page.data.entity.attributes.get();
for (var i in attributes) {
Xrm.Page.getControl(attributes[i].getName()).setDisabled(false);
}
}
}

**For CRM 2011 Training, please check out our CRM Training page. Please share |Like in Facebook if you feel like this page is useful.

Advertisements

About Dynamics CRM Guru

We are a group of CRM Consultants and have rich experience in all Microsoft CRM versions. Currently we provide training in Microsoft CRM 2015/CRM 2013 and CRM 2011.

Posted on December 14, 2012, in Microsoft CRM 2011, MS CRM 2011 Training and tagged . Bookmark the permalink. Leave a comment.

Leave a Reply

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

%d bloggers like this: