Skip to main content

Disable Section Fields Javascript Model Drive App | Dynamics 365 CRM | Power App

This is JS to disable the section attributes


function disableSec(executionContext) {

    disableAllControlsInSection("invoice information", executionContext);

}

function disableAllControlsInSection(sectionLabel, executionContext) {
    var formContext = executionContext.getFormContext();
    var tabs = formContext.ui.tabs;

    for (var i = 0; i < tabs.getLength(); i++) {

        var tab = tabs.get(i);

        var sections = tab.sections;

        for (var j = 0; j < sections.getLength(); j++) {

            var section = sections.get(j);

            if (section.getLabel().toLowerCase() === sectionLabel.toLowerCase()) {

                //debugger;
                if (formContext.getAttribute("statuscode").getValue() == 4) {
                    DisableForm(formContext);
                }
            }
        }
    }
}

function DisableForm(formContext) {
    formContext.ui.controls.forEach(
        function(control, index) {
            if (control.getControlType() != "subgrid")
                control.setDisabled(true);
        });
}

Comments