Rows.each()
This article is about the each() function of the Rows object.
Rows.each()
Iterates the execution of a function over the matched rows.
Returns a UdbPromise object.
Like Rowset.each(), this function settles all the calls before resolving, even if one or more of them are rejected.
Syntax
$.udb( *ds* ).rows( [rowRef1], [rowRef2] ).each( *function*( *index*, *row* ) )
.then( ( *result* ) => {
// success
});
$.udb( *ds* ).rowSet( *rowSet* ).rows( [rowRef1], [rowRef2] ).each( *function*( *index*, *row* ) )
.then( ( *result* ) => {
// success
});
The required ds parameter is a data source selector.
The optional rowSet parameter is a rowset identifier. If the .rowSet() clause is omitted, then .rowSet('current') is assumed.
The optional rowRef1, rowRef2 are row selectors. If omitted, all records in scope are addressed.
The required function is the function that is to be called for each of the matched rows.
Index is the array index of the row for which the function is executed. This index is 0-based.
Row is a single-row Rows object wrapping the row itself. Effectively, row is the same object as returned to the function call as this.
The result passed to the .then() clause is an array with, for each matched row, an object describing whether that call was fulfilled or rejected (in the same shape as the standard Promise.allSettled() result).
Example
$.udb('EMP').rows().each((index, row) => {
console.log(row.cols('EMP_NO').val());
});