如何分配一个变量作为其他变量的差异?

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

我们正在使用 NetSuite 中的 FreeMarker。

现在我们需要一个变量作为其他变量的差值。 我的想法是:

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

但是系统说:

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)??

然后我试了这个:

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

但是结果是一样的

如何将一个变量赋值为其他变量的差值?

终于找到解决方法了

错误是在“<#list record.apply as apply>”中声明了"apply",但我在它前面使用了apply.total。

现在我声明如下并且它适用于我:

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

感谢您的贡献。