Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

PI Connector for UFL

Learn about FOREACH() statement

  • Last UpdatedJan 28, 2025
  • 1 minute read

With the FOREACH() code flow control, you can loop through sets of items in the following well-known data formats: JSON and CSV.

Below simplified example explains the principle. The syntax shows how to iterate through a collection of comma-separated items, print them, and add the individual items to a variable of the Collection data type.

FOREACH (CsvGetItem(__MESSAGE,",")) DO

Print(__ITEM)
Values = Add(__ITEM)
ENDFOR

The formal syntax is the following:

FOREACH(<condition>) DO <expression(s)> ENDFOR

The <condition> in the FOREACH() statement can only include one of the following functions:

  • CsvGetItem

  • JsonGetItem

They both return Boolean. For details about their input parameters, see Functions for extracting from well-known data formats in Learn about functions and operators.

The expression(s) within the body of the FOREACH() statement can be arbitrary expressions that the UFL logic supports, including the nested FOREACH().

During each iteration, the JsonGetItem() function populates the predefined variables __ITEM_Name and __ITEM. Both variables are strings. In order to convert the __ITEM to Number,Int32 or DateTime, assign it to another variable which is of the required type.

TitleResults for “How to create a CRG?”Also Available in