Good Morning,
I am trying to add several values using IF statements and within those IF statements I am using TAG functions. I have tried to add these values without any TAG functions and it works fine. It currently will only show the first IF statement value that is TRUE. Attached is a sample of my Expression.
There's your answer. Don't use the tag() function. Create custom properties with indirect tag bindings for each would-be tag() function, and use that property in your complex expression.
@pturmel Thank you for referring me back to my original request from many months ago. I have been working with the custom properties and believe I can apply them to this problem. Thanks again…
Thanks for the info. I do agree custom properties are the way to go, especially if you have to reference those tags several times and using several tag() is silly.
FYI, v8.0.16 has a fix for tag()…
“Use of the tag() function inside a tag in a UDT can potentially lead to a blocking delay of 30 seconds when the tag is initialized.”
I noticed that problem and fix. Significant, as tag() is appropriate within expression tags. That fix has nothing to do with the drawbacks of using tag() anywhere else.
I wanted to clarify the Custom Property and where I would put them inside of my template. I have a template with properties and then inside of that template I have the expression I am trying to use to sum the values X4. Would those custom properties with indirect bindings live in the Template properties or in the Display where I am doing all of the If statements? I have tried both places but have not been successful. Thank you for your reply.
I'm not precisely sure what you mean by "Display" here.
Anyways, template properties qualify as custom properties, but can only have bindings in the Vision window that holds the template, or an outer template that nests the given template. Template internal properties are custom properties that are invisible to the Vision window or outer template but can have bindings inside the template. Expression bindings inside the template, both for template internal properties and for custom properties on a template's components, can use values from anywhere else inside the template.
Choosing where to create a custom property to hold an intermediate value (like an indirect tag binding) is pretty open, since bindings can draw from all over in your template. I like to keep custom properties on the component where they are used, if they are only used in one place. Then on any container where they have multiple consuming expressions. I would use template internal props if the intermediate value is used all over the place.
Note that you do not have any binding option to expose template internal calculations to the vision window or outer template of a nesting situation. Template internals must use scripting to write to exposed template properties, and that is only useful for the single-instance template holder component. Repeater/Canvas usage doesn't expose them at all.
Ok. So your expression with all the “if” functions is on a numeric display? And the indirect tags you need within that are only for that numeric display’s use? Then I’d create custom properties for them right on that display component.
All of Phil’s comments are correct… The “then” portion of your “if” statement appears to return an empty string, change this to a 0 and it might work a bit better. I would still follow Phil’s advice.
It doesn't matter where they live, both should work. Just try to be consistent across your code base. The only thing you have to watch out for with templates is that they have two types of properties: properties that come from the parent, and internal properties. So perhaps it's easier to define them on the display component.
The procedure:
Right click on the component > Customizers > Custom properties
Add a custom property for every tag() call in your expression (with a name you can understand, and the correct datatype)
For every custom property, define an indirect binding with the parameters as you had the tag() expressions (hint, you can right click on a property, and copy the binding to another property, that may make the configuration faster)
replace all the tag() functions in the expressions with references to the custom properties
That will clean up the expression a whole lot, and make it easier to see what's going wrong. If you want to clean up the expressions more, you can even add custom properties for the if clauses (one property per line on your expression).
The end result will be a lot of understandable datapoints, that can be used to troubleshoot where something is going wrong.