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

$-

Variable

variable

A $-Variablevariable 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$-VariablevariableA comma separated list of Expressions expressions which will be processed once for each entry in set.

...

  • Its return value is the last statement executed in the last iteration.
  • 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.

See also:

Examples


In the first two examples, let

...

  1. Assign the value of the customer type to the $-Variable $customerType.
  2. The first expression then increments the value of $total by 1 (i.e. counting the total number of types in the list).
  3. The second expression checks if the type is "Business" and if so calls continue() which causes forEach() to immediately skip to the next customer type in customers.type and starts again from the first expression (i.e. it does not reach the 3rd expression to increment the $-Variable $nonBusiness).
  4. If the type is not "Business" the third expression will be processed increment a count of the non-business types.
  5. The final expression is evaluated and the result added to the result Array of the forEach() function.

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.

...

Then the next attribute might be NonBusinessCustNumber, and you could write the number of non-business customers calculated in the loop to this attribute simply using the expression:

$nonBusiness

See Also