Thursday 24 November 2022

Dynamics 365 – Make the Form Readonly with Javascript

 

Dynamics 365 – Make the Form Readonly with Javascript

To make the form read-only in Dynamics 365 you have 2 options. Either changing record status to Inactive or making all form fields disabled with Javascript.

Changing record status to Inactive might not suitable for some business cases. For example you might want to make your form read-only based on an attribute. If you change your status to inactive, it might trigger record cascading, which will cause to setting related child record status to also inactive. In addition your record won’t show up under Active records view.

If you think this is not the best way for you, then you can use Javascript. The below piece of code sets all form fields to read-only dynamically. It will loop through your form controls(tabs, sections, feilds) one by one and disable them.

disableForm: function (executionContext) {
let formContext = executionContext.getFormContext();
let formControls = formContext.ui.controls;
formControls.forEach(control => {
if (control.getName() != "" && control.getName() != null) {
control.setDisabled(true);
}
});
}
view rawFormReadOnly.js hosted with ❤ by GitHub

No comments:

Post a Comment

Git Basic working