Skip to main content

Notifications

Announcements

No record found.

DISABLE ALL FORM FIELDS IN DYNAMICS 365 USING JAVASCRIPT

To make the form read-only in Dynamics 365 you have 3 options: changing record status to Inactive, Business rule, JavaScript.

The purpose of this article is to know how to make all form fields disabled with JavaScript.

Changing record status to Inactive might not very suitable for some cases where cascading rules might be applied to children records.

On the other hand, even though it is a low code solution, using business rule to make all fields read-only will be very time consuming especially if a field is removed from the form or a new field is added to the form.

However, using JavaScript will allow you to set all form fields to read-only dynamically with a small piece of code and you can do it based on a certain condition of an attribute value.
  1. Make read-only the whole fields of a form based on a certain condition
    Form readonly

  2. The below function can be called on the event you need and will loop through all the fields to make them read-only

    // Disable all form fields
    function disableAllFormFields(context) {
    var formContext = context.getFormContext();
    formContext.ui.controls.forEach(function (control, i) {
    if (control && control.getDisabled && !control.getDisabled()) {
    control.setDisabled(true);
    }
    });
    }
Hope This Helps!

This was originally posted here.

Comments

*This post is locked for comments