D365 – Set Editable Subgrid Columns to Read-Only Using JavaScript

Make All Columns Read-Only

JAVASCRIPT
Disabled_XXXXX_SubGridOnSelect: function (ExecutionContext) {
    let that = this;
    let objFormContext = ExecutionContext.getFormContext();
    let entObject = objFormContext.data.entity;
    entObject.attributes.forEach(function (attribute) {
            let allColumnControl = attribute.controls.get(0);
            allColumnControl.setDisabled(true);
        });
}
Click to expand and view more

Make Specific Columns Read-Only

JAVASCRIPT
Disabled_XXXXX_SubGridOnSelect: function (ExecutionContext) {
    let objFormContext = ExecutionContext.getFormContext();
    let entObject = objFormContext.data.entity;
    entObject.attributes.forEach(function (attribute) {
        let columnName = attribute.getName();
        if (
            columnName == "your field name 1" ||
            columnName == "your field name 2" ||
            columnName == "your field name 3" ||
            columnName == "your field name 4" ||
            columnName == "your field name 5" ||
            columnName == "your field name 6") {
            attribute.controls.get(0).setDisabled(true);
        }
    });
}
Click to expand and view more

Binding

Open the form, select the editable subgrid, and then bind the method (don’t forget to check “Pass execution context as first parameter”).

Bind JavaScript to Editable Subgrid

Copyright Notice

Author: Donghai

Link: https://gdhblog.com/posts/d365/set-editable-subgrid-columns-to-read-only/

License: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Please attribute the source, use non-commercially, and maintain the same license.

Comments

Start searching

Enter keywords to search articles

↑↓
ESC
⌘K Shortcut