Expression as parameter in UDT

Curious has anyone passed a parameter into a UDT which is an expression. Then have an expression tag execute it. Typically, the expression tag just returns the parameter as a string.
I see quite a few posts asking about this which either fade away without much response or end with someone suggesting tag().

I found a work around where if you export the UDT config, and update the expression field using a text editor to be like below, it works.

"expression": {"bindType":"parameter","binding","{expressionParam}"}

(where expressionParam is a UDT parameter which contains the expression as a string)

In my example, I was using a few relative tag paths in expressionParam, and it also saves having to multiple parameters and or using the tag() function.

ie replace 'tag(param1) + tag(param2)' with '{[.]tag1} + {[.]tag2}'

I currently see 2 negatives with this work around. Wondering if there are any more pros/cons to consider before I start using it properly:

- When you open the UDT in Ignition, there is no visibility on the changes made in text editor. The expression field of the tag is blank. But it does correctly run the expression defined in expressionParam. Its not great for visibility, but I could include something in the Meta Data/Documentation I guess.

- To me this seems a bit of a ‘hack’, so I assume probably not encouraged/supported by IA. Is it something I should avoid using in case IA see it as a security issue and block it in future releases (currently v8.1.48).

You can use system.tag.configure() to assign an expression using a dictionary with the binding details. Passing through a UDT parameter is unlikely to work.

That’s why I’m unsure if I should continue pursuing this or not. It does seem to work, but maybe it’s not supposed to? That or I didn’t understand your reply.

UDT Instance

UDT Definition

I fully understand I can do this in other ways, and I probably will end up doing one of those ways, mainly because the binding is hidden from the popup tag editor. But also, it would be nice if it was a UDT like this, so it was closer aligned with my other tag structures.

Hmmm. I didn't expect it to work. Not the first time that Ignition has surprised me in a good way. Carry on. :grin:

2 Likes