Monday, September 12, 2011

Disable All Fields in a Section Based on the Value of Another Field (CRM 2011)

//THIS FUNCTION DISABLES ALL THE FIELDS IN THE SECTION LABELED "FINANCIAL INFO"
//IF A BOOLEAN OPTION FIELD IN ANOTHER SECTION CALLED new_toggleSectionFlds = TRUE

function DisableSectionAttributes() {
    function setFldDisabled(ctrl) {
        ctrl.setDisabled(true);
    }
    function setFldEnabled(ctrl) {
        ctrl.setDisabled(false);
    }
    var toggleSectionFlds = Xrm.Page.getAttribute('new_toggleSectionFlds').getValue();
    var ctrlName = Xrm.Page.ui.controls.get();
    for (var i in ctrlName) {
        var ctrl = ctrlName[i];
        var ctrlSection = ctrl.getParent().getLabel();
        if (toggleSectionFlds == true) {
            if (ctrlSection == "Product Info") {
                setFldDisabled(ctrl);
            }
        }
        else {
            if (ctrlSection == "Product Info") {
                setFldEnabled(ctrl);
            }
        }
    }
}

No comments:

Post a Comment