Learn about FOREACH() statement
- Last UpdatedJan 28, 2025
- 1 minute read
- PI System
- PI Connector for UFL 1.3.2.139
- Connectors
With the 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:
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 statement can be arbitrary expressions that the UFL logic supports, including the nested .
During each iteration, the 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.