isNull() always returning false

I have created a UDT called MyUDT.
The UDT has one parameter; a String called UDTParameter.
The UDT has one tag; an expression tag called IsParameterNull with the expression isNull({UDTParameter})

I am expecting that when I create an instance of this UDT, if I do not define the parameter, my expression tag will be true. However, it is always false.

What am I missing here?

Screen Shot 2022-04-12 at 4.59.57 pm

I’m having difficulty proving it but I suspect that since you have defined the parameter as a string that it is now an empty string and not a null.

Try {UDTParameter}="" or if({UDTParameter}="", true, false) in your expression instead.

The isNull expression is only viable for a tag not for parameters.
The best way to do should be to check like a @Transistor mention with a if expression.
But i don’t think that a null parameter is see as a empty string.

That may not be quite correct. The manual says,

//Returns "Value is Null" if the property is null, and the value otherwise.
if` `(isNull({Root Container.MyProperty}), ` `"Value is Null"` `, {Root Container.MyProperty})

This if for a property in a container not a udt parameter.

It’s definitely null and not an empty string. The way I first discovered this was that I have a UDT which has three parameters:

Device Name

I use Device Name and PLC Tag to build the OPC path, and PID tag is just the PID tag of the device for documentation purposes, e.g. TT1001.

Then, I have an expression tag in the UDT called PIDTag. The expression was originally:

if({PID Tag} = "", {PLC Tag}, {PID Tag})

…basically, if a PID tag is specified when the instance is created, use the specified PID tag. If no PID tag is specified, use the PLC tag as the PID tag, because 99% of the time, the PLC tag will actually be the PID tag, so I can save 7 seconds of typing by making that the default assumption.

But, it didn’t work, because the PID Tag parameter was not “” (i.e. blank), it was null. So, I changed my expression:

if({PID Tag} = "" || isNull({PID Tag}), {PLC Tag}, {PID Tag})

…but it still doesn’t work, and I’ve established that it’s because isNull is always returning false.

So my parameter is not “” (blank), and isNull() refuses to acknowledge that it’s null, and I’m stuck.

My workaround is to go into all my UDT definitions, and in each parameter, insert a blank space, then come back and delete it. Now my parameters are “” (blank) and no longer null, so my original expression works. But it’s a hacky workaround and I hate not knowing why it doesn’t work.

I’m going to open a bug ticket for this… it’s very easy to mock up with the information in your original post.

What the isNull expression sees, for some reason, is a String value of "{ParamName}" instead of null. (with whatever your actual param name is)

1 Like

Thanks, glad it’s not just me! Is there a way to track the status of the ticket so that I can see when it gets fixed?

This post is linked in the issue, so somebody should come back and update it… but the best/official way would be to open a ticket with support instead. They are supposed to notify customers when an associated issue is closed…

You can probably save some time by referencing this forum post and IGN-5870.

1 Like

Thanks, will do!