首页 > 解决方案 > 如何使用 Dynamics 365 中的 JS 在子网格中循环行(当前行除外)

问题描述

我能够使用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
    }
}

标签: javascriptdynamics-crmmicrosoft-dynamics

解决方案


您应该能够使用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();
        });
    });

阅读更多


推荐阅读