Nested expression weirdness

Not sure if this is a bug, I am probably just doing this wrong. Eventually, I want to check two values and if either of them are not 0 then I want to write some text as well as the answer to a calculation.

To keep the example simpler, I have replaced some long tags and maths with simple number and equations, but the problem still exists:

[= ‘0’ != ‘0’ || ‘1’ != ‘0’ ? 'Account ’ : ‘’]
[= ‘0’ != ‘0’ || ‘1’ != ‘0’ ? ‘Account [=(10-5)]’ : ‘’]

This gives me an output (that I expect) of:

Account 5

But, only the last line is what I really want. If I comment out the other two lines, this is what I end up with…

– [=(10-5)]
– [= ‘0’ != ‘0’ || ‘1’ != ‘0’ ? 'Account ’ : ‘’]
[= ‘0’ != ‘0’ || ‘1’ != ‘0’ ? ‘Account [=(10-5)]’ : ‘’]

And the output is…

’ : ‘’]

Very strangely, if I incorrectly comment out the lines, and don’t leave the space after the “–” then the preview in the template editior shows correctly (although the actual printout from the printer is incorrect).

Any idea how I could get this to work?

Well to test if comment out is a factor try deleting them rather than comment, will rule that out buts punting it.

Sorry, I should have siad - deleting the other statements also leads to the weird output.

Commenting properly and deleting produces the same, strange output.

What’s reallty weird is the commenting incorrectly leads to the correct output within the template editor preview. By “incorrect commenting” I mean (Note the lack of space after the comment markers)…

–[= ‘0’ != ‘0’ || ‘1’ != ‘0’ ? 'Account ’ : ‘’]
[= ‘0’ != ‘0’ || ‘1’ != ‘0’ ? ‘Account [=(10-5)]’ : ‘’]

You should use {CALL:X} script.
In printer template square bracket use to validate if it zero value then display nothing as well. So, this would cause parsing error.

I am looking in to this, so is the idea that I would put the mathematics that I want calculated in an external function and call that function using CALL?

Is there any way to handle this all within the printer template without creating these external functions?


Try this
<L>[Account [[='0' != '0' ? 10-5 : '']]] This will have empty line
[<L>Account [[='0' != '0' ? 10-5 : '']]] This has no empty line

Ahhh - I see what you’ve done there. Hadn’t thought of doing it in that way - very smart.

Thanks very much :slight_smile:

You cannot nest [=expressions], and there should be no need to do so. If you think you have some logic that requires that complexity, then you need to make a JS script containing a function and invoke it via {CALL:handlerName.functionName(pa,ra,me,te,rs)}.

Try one of these:

[= '0' != '0' || '1' != '0' ? 'Account ' + (10-5) : '']
[= '0' != '0' || '1' != '0' ? 'Account ' + TN(10-5) : '']

You can also wrap those in more [brackets] as @sukasem shows if you are trying to avoid printing blank lines. What that does is evaluate the inner-most bracket content, and if blank or zero, then the entire content of the outer-most bracket content is not printed.

Commented lines in a Template require a space after the --


Thanks @QMcKay

Thinking with my JS hat on, I had tried what you suggested, and figured, since we are already in a JS expression there was no need to start another one, but it just doesn’t seem to work in the way you have set out your examples, and I couldn’t think why.

With a reasonable background in JS, my first approach was to do what you are suggesting, but when I put it in to a template it doesn’t show anything. Any ideas why (I would prefer to do it this way because for me, it’s much more understandable).

Ah the Plus sign to join.

Always forgot [=…] is actually JavaScript and JS use + to join string.

1 Like

But thats the thing, it’s not working as I’d expect. Perhaps because the result of the math is not a string, but I also tried toString(10-5), but that didn’t work either.

I think the issue is because we are trying to add a string to an intefer?

Anyway, you have working solution :wink:

1 Like

How so?

<L00>[= '0' != '0' || '1' != '0' ? 'Account ' + (10-5) : '']

1 Like

That is so weird. It’s working perfectly now. I don’t know what I was doing before. Clearly some kind of brain fart! :blush:

Thanks @QMcKay