如何在 Dynamics 365 中使用 JS 在子网格中循环行(当前行除外)

How To Loop Rows (other than current row) in Subgrid using JS in Dynamics 365

我能够使用 web 资源.

读取由 OnChange 触发的子网格单元格值

接下来,我需要遍历子网格中的剩余行(当前行除外)并读取每一行的每个单元格值。

请问如何实现?


当前代码片段:

function SetNA(context) {

    debugger;

    //id of the subgrid
    var id = formContext.data.entity.getId();

    // get the attribute which fired the onchange.
    var changedFirstNameAttr = context.getEventSource();

    // get the container for the attribute.
    var attrParent = changedFirstNameAttr.getParent();

    // var FirstName Field Attribute
    var changedFirstNameField = attrParent.attributes.get("firstName");

    // get the value of the changed first name value
    var changedFirstNameValue = changedFirstNameAttr.getValue();

    alert(changedFirstNameValue);

    if (changedFirstNameValue != null)
    {
        //loop through other rows in the subgrid, and read each cell value
    }
}

您应该能够使用 getRows 方法来拉取和迭代所有可编辑的网格行并实现您想要的。

var gridRows = gridContext.getGrid().getRows();

//loop through each row to get values of each column
gridRows.forEach(function (row, i) {
    var gridColumns = row.getData().getEntity().getAttributes();
    //loop through each column in row
    gridColumns.forEach(function (column, j) {
        var atrName = column.getName();
        var atrValue = column.getValue();
        });
    });

Read more