[Solved] Substring() on template instanceName


Seems like a bug… crawling in my head… or in Ignition? :ant:

I have a simple template called PartTrackOverlay with a label component. The text property of the label has this binding expression:
substring({PartTrackOverlay.instanceName}, 4) //simple enough, right?

But, it keeps throwing this error.

Exception: Error executing expression binding on
caused by StringIndexOutOfBoundsException: String index out of range: -4

The instanceName of each template is Part1, Part2, …Part32.
Also… I would have thought the error would be 4, not -4. Perhaps a clue, but I am not sure where it leads.
The only integer arg it will take is zero. Whatever arg I put in there for the offset shows up in the error as a negative number.

And, after closing the error, the label is correct on the template in the designer.

Any wisdom?


It sounds like a timing issue of the label source not being populated before the expression call.
Wrap it in a try and it should stop the error.

try(substring({PartTrackOverlay.instanceName}, 4),’’)

1 Like

Thank you, that worked! I am still a bit befuddled by the error, especially when a left() or right() call does not produce any error… only substring(). Interesting.

Again, thanks.