JSDO properties, methods, and events reference : foreach( ) method
  

foreach( ) method

Loops through the records of a table referenced in JSDO memory and invokes a user-defined callback function as a parameter on each iteration.
With each iteration, it also sets the current record as the working record and passes it as a parameter to the callback function. This function can then operate on the working record and return a value indicating whether the foreach( ) terminates the loop or invokes the callback function on the next working record of the table.
If the referenced table has child tables in the same multi-table resource, and the useRelationships property is true, with each iteration through the loop, the working record of the result set for each child is set to the first record as determined by the relationship to its respective parent.
Return type: null
Applies to: progress.data.JSDO class, table reference property (JSDO class)
Working record: After completing execution, the working records of the associated table, and any child tables, are the most recent working records established when the method terminates the loop.

Syntax

jsdo-ref.foreach ( funcRef )
jsdo-ref.table-ref.foreach ( funcRef )
jsdo-ref
A reference to the JSDO. You can call the method on jsdo-ref if the JSDO has only a single table reference.
table-ref
A table reference on the JSDO.
funcRef
A reference to a JavaScript callback function that returns a boolean value and has the following signature:
Syntax:
function [ func-name ] ( jsrecord-ref )
Where func-name is the name of a callback function that you define external to the foreach( ) parameter list and jsrecord-ref is a JSRecord object reference to the next working record on the table reference. You can then pass func-name to the foreach( ) method as the funcRef parameter. Alternatively, you can specify funcRef as the entire inline function definition without func-name.
The foreach( ) method executes your funcRef callback for each record of the table reference, making this record the working record and passing it in as jsrecord-ref. You can then access the field values of the working record using the data property on jsrecord-ref or any field references available from the table reference. You can also invoke other JSDO methods, for example, to operate on the working record, including additional calls to foreach( ) to operate on working records of any child tables.
Your funcRef callback can terminate the foreach( ) loop by returning false. If the callback does not return false, the loop continues.
If the table reference references a child table in a multi-table resource, when the useRelationships property is true, foreach( ) uses the relationship to filter out all but the child records of the working record in the parent table. However, if the working record of the parent is not set, foreach( ) throws an error. If useRelationships is false, the loop includes all records of the child table and no error is thrown.

Example

After creating a JSDO for a dsCustomer resource and loading it with record objects, the following code fragment shows the foreach( ) method looping through eCustomer records in JSDO memory and displaying the CustNum and Name fields from each record, one record per line, to the current HTML page, and also to the console log:
jsdo = new progress.data.JSDO({ name: 'dsCustomer' });
jsdo.subscribe( 'AfterFill', onAfterFillCustomers, this );

jsdo.fill();

function onAfterFillCustomers(jsdo, success, request) {
  jsdo.eCustomer.foreach( function(customer) {
    document.write(customer.data.CustNum + ' ' + customer.data.Name + '<br>');
    console.log(customer.data.CustNum + ' ' + customer.data.Name);
  } );
};

See also:

data property, find( ) method, progress.data.JSRecord class