Conditional expression on tags that are often null? [BEGINNER]

Hello,

I have a UDT containing multiple status integers with the same general meaning:

1 - Complete
2 - Warning
3 - On Hold

If any one of the status ints is equal to 3, the “on hold” designation applies to the entire instance.

I would like to add a boolean expression tag to this UDT that checks the values of all the status ints and evaluates as true if any of them is equal to 3.

The expression I wrote basically looks like: {[.]StatusInt1} > 2 || {[.]StatusInt2} > 2 … || {[.]StatusIntN} > 2

This works sometimes, but other times the boolean tag shows a red exclamation with “Error_ExpressionEval”

I think this is happening because the status ints are being set dynamically and the expression doesn’t like evaluating on a bunch of null values.

Any ideas on how I can do this cleanly or a point in the right direction would be greatly appreciated!

You can return a default value by using the coalesce expression.

https://docs.inductiveautomation.com/display/DOC81/coalesce

I also might be tempted to do something more like:

max({[.]StatusInt1,{[.]StatusInt2},...) = 3

There are several ways to accomplish what you’re trying to do.

2 Likes

If it’s equal to 3, use = 3.

the coaslesce expression function will do what you want. If you use coalesce(x, true) and x is null, it will return true.

1 Like

Putting these two replies together, I think one of the following two solutions would work well for you:

Use coalesce to “safety check” each StatusInt in the expression. It would look something like this:

coalesce({[.]StatusInt1}, 0) = 3 || coalesce({[.]StatusInt2}, 0) = 3 || ...

Another possibility is to do this “safety check” in the expression for each StatusInt itself. You could, for example, say that the value 0 means the same thing as what null did before. That way, you’d only ever be dealing with non-null values, and your original solution would work.

StatusInt1 -> coalesce(<previous_expression>, 0)
{[.]StatusInt1} = 3 || {[.]StatusInt2} = 3 || ...
1 Like

Thanks to all!

max(…) = 3 works like a charm :^D