How To Loop Rows (other Than Current Row) In Subgrid Using JS In Dynamics 365

I am able to read a Subgrid cell value triggered by OnChange using web resource.

Following which, I would need to loop through the remaining rows (except current row) in the subgrid and read each cell value for each row.

May I know how can it be done?

Current code snippet:

function SetNA(context) {


    //id of the subgrid
    var id =;

    // 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();


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


You should be able to use getRows method to pull and iterate through all the editable grid rows and achieve what you want.

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