Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Function: forEach()

Iterates over an Array or Recordset and processes a script for each entry.

...

ArgumentTypeDescription
$var$-VariableA $-Variable which will be set to each item in set in turn before script is processed.
setArray or RecordsetThe set of items which will be iterated over.
script$-VariableA comma separated list of Expressions which will be processed once for each entry in set.

forEach() is like every other function in that it returns a value. 

  •  Its Its return value is the last statement executed in the last iteration.
  •  All All the $-variables used in the call to forEach() keep their values between iterations.
  • All the $-variables used in the call to forEach() will be available after it has returned.

...

The forEach() function above therefore returns an Array of the first 6 characters of each non business customer type in the supplied list. The values of $total (a count of all customer types), $nonBusiness (a count of all non-business customer types) and $customerType (the last customer type processed) will be available to subsequent Attribute Expressions for the current Stream Item calculation.


Commonly, you might not want to return a list from forEach(), but calculate some values in the loop to use later. For example, if you had an attribute TotalCustNumber, you might create an attribute expression:

...