Wednesday, August 29, 2012

CRM 2011 - Disabling all Fields on a Form to make read only form //based on two option field by javascipt

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);
        }
    });
}

function setupFormVisiblity()
{
    var dependantControl = Xrm.Page.ui.controls.get("jmh_isrmsstockitem");
        if ((dependantControl != "undefined") && (dependantControl != null)) 
{
            var attribute = dependantControl.getAttribute();
            var depandantFieldValue = attribute.getValue();
            //set visible based on depandant fields value
            if (depandantFieldValue == true) //based on two option field
 {
          disableFormFields(true);
   }
}
}

Note: call  setupFormVisiblity  javascipt method OnLoad Event of Form only..

No comments:

Post a Comment