Search code examples
netsuitefreemarker

How to assign a variable to be the difference of other variables?


We are using the FreeMarker in NetSuite.

And now we need a variable to be the difference of other variables. My idea is as follows:

<#assign paymentValue = apply.total- apply.due>

But systems said that:

Tip: If the failing expression is known to be 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)??

Then I tried this:

<#if apply.total??>${apply.total}<#else>0</#if>
<#if apply.due??>${apply.due}<#else>0</#if>
<#assign paymentValue = apply.total-apply.due>

But the result is the same.

How to assign a variable to be the difference of other variables?


Solution

  • Finally, I found the solution.

    The error is that the "apply" is declared in "<#list record.apply as apply>", but I use the apply.total before it.

    Now I declare as follows and it works for me:

    <#list record.apply as apply>
    <#assign paymentValue = apply.total - apply.due>
    

    Thanks for your contribution.