Tuesday 12 March 2013

Disable all fields in CRM 2011 based on Statuscode using Javascript


function DisableFields() {
    if (Xrm.Page.data.entity.attributes.get("statuscode").getValue() != 1) {
        disableFormFields(true);
    }
}
function doesControlHaveAttribute(control) {
    var controlType = control.getControlType();
    return controlType != "iframe" && controlType != "webresource" && controlType != "subgrid";
}
function disableFormFields(onOff) {
    Xrm.Page.ui.controls.forEach(function (control, index) {
        if (doesControlHaveAttribute(control)) {
            control.setDisabled(onOff);
        }
    });
}

Save this code on webResources and call DisableFields method on page OnLoad.

No comments:

Post a Comment