Microsoft Dynamics 365 CE Disable All fields With JavaScript (Read Only Form)

There is a way to disable all your fields control in form through javascript.

function disableAllFields(executionContext) {
    try {
        var formContext = executionContext.getFormContext();

        var status = formContext.getAttribute("new_status").getValue();

        if (parseInt(status) != 275380000 ) {  //completed  --> If you want to disable based on condition.
            var formContext = executionContext.getFormContext();

            formContext.ui.controls.forEach(function (control, i) {
                if (control && control.getDisabled && !control.getDisabled()) {
                    control.setDisabled(true);
                }
            });
        }
    }
    catch (err) {

    }
}

The function is now ready now you can use this function on page load, on field change event.

Leave a comment