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.

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 )

Facebook photo

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

Connecting to %s