RE: Advanced PDF print statement when a condition is met
Using advanced pdf, I am trying to modify a picking sheet to print a statement when {shipcomplete} is Yes. I am using the <#if> but have issues when the field is null.
I tried the following
<#if record.shipcomplete?has_content>
<#if record.shipcomplete == “Yes”>
SHIP COMPLETE
</#if></#if>
When I do so, I receive the error below.
If the failing expression is known to legally refer to something that’s sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
I am not familiar with the myoptionalvar and do not know how to incorporate it into the picking sheet.
Any help will be greatly appreciated.
I think you are getting confused.
The error explanation is that you have a variable that may or may not be present / populated and in the explanation it’s called “myOptionalVar” i.e. “my variable that is optional”.
It’s explaining that you can use a default if your value is not populated like this:
myOptionalVar!!myDefault where “myDefault” is a variable holding a default value to fall back on.
Alternatively you can use an IF statement with “??” to positively identify if a variable is populated.
I cannot recall the value of a checked checkbox in adv print, but the apache freemarker docs seem to imply it’s true or false
https://freemarker.apache.org/docs/dgui_template_exp.html#dgui_template_exp_direct_boolean
Not that this is your specific issue, it seems more likely the variable is not present.