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