Iterating through an array-tag to determine if value is present
Casus: A camera is selected on a video-wall if it’s ID (UDT-parameter) is present in a tag of the type Integer array (external system). So I want to use an expression-tag to determine if the camera is selected (boolean).
Approach: Iterate through the array with forEach (or where?) and compare each value to the integer ID-value. If found -> true, else false
Initial expression
forEach returns a list if expression is met?
Then check if this list has one or more entries.
if(
len(
forEach(
{[~]MSBS/SLKRS1_I1/CCTV/Pnl/STS/CameraNr.value},
it() = {ArrayID}
)
) > 0,
true,
false
)
Status: Error in the tag (Error Config)? What do I do wrong?
Tips:
forEach()
always returns a list. But per my previous reply, use where()
instead of forEach()
. Do not wrap an if()
around the whole thing, as a comparison with len()
yields a boolean directly.
Improved expression
Note: I've moved the source (array) tag to be in the same folder as the expression-tag in order to supply an export-file (attached) if anybody is interested in reproducing/solving the issue.
len(
where(
{[.]CameraNr.value},
it() = {ArrayID}
)
) > 0
Previous improvements applied, still an Error_Configuration (Error writing to Geselecteerd.value: Bad_Unsupported)
ExpressionTagAndSource.json (784 Bytes)