【发布时间】:2019-07-18 18:58:51
【问题描述】:
我有以下 NetSuite 高级 PDF HTML 模板代码给我一个错误:
<#if record.item?has_content>
<table class="itemtable" style="width: 100%;"><!-- start items --><#list record.item as item><#if item_index==0>
<thead>
<tr>
<th colspan="4">Item Code</th>
<th colspan="12">Item Description</th>
<th align="right" colspan="2">UOM1</th>
<th align="right" colspan="3">${item.quantity@label}</th>
<th align="right" colspan="3">UOM2</th>
<th align="right" colspan="4">Unit Price (excl. VAT)</th>
<th align="right" colspan="3">${item.amount@label}</th>
</tr>
</thead>
</#if><tr>
<td colspan="4">${item.item}</td>
<td colspan="12">${item.description}</td>
<td align="right" colspan="2">${item.custcolsyn_uom} ${item.custcolsyn_unit_measure}</td>
<td align="right" colspan="3">${item.quantity}</td>
<td align="right" colspan="3">${item.units}</td>
<td align="right" colspan="4"><#if item.rate?has_content>${item.rate?keep_before_last(".")}.${item.rate?keep_after_last(".")[0..1]}<#else> </#if></td>
<td align="right" colspan="3">${item.amount}</td>
</tr>
</#list><!-- end items --></table>
</#if>
问题出在这行:
<td align="right" colspan="4"><#if item.rate?has_content>${item.rate?keep_before_last(".")}.${item.rate?keep_after_last(".")[0..1]}<#else> </#if></td>
看起来 FreeMarker 正在评估以下部分
${item.rate?keep_before_last(".")}.${item.rate?keep_after_last(".")[0..1]}
即使订单项没有任何价格信息。没错
<#if item.rate?has_content>
应该阻止这种评估的发生。我试图只保留 2 位小数的货币数据,而我尝试的所有其他方法都丢失了货币符号。
我们使用的是最新版本的 NetSuite (2018.2)。
错误信息是:
The template cannot be printed due to the following errors:
Error on line 239, column 95 in template.
Detail...
Range start index 0 is out of bounds, because the sliced string has only 0 character(s). (Note that indices are 0-based).
The blamed expression:
==> 0..1 [in template "template" at line 239, column 128]
----
FTL stack trace ("~" means nesting-related):
- Failed at: ${item.rate?keep_after_last(".")[0..1]} [in template "template" at line 239, column 95]
----
Please contact your administrator.
任何人对我做错了什么或如何解决此问题有任何想法?
【问题讨论】:
-
如果费率以
.开头,您可以获得此异常 -
利率为空/空/空白
-
item.rate是数字还是字符串?试试:${item.rate?is_number?c。 (或者如果 NetSuite 是从某个古老的 FM 版本中分叉出来的,因此不知道?c,那么使用?string而不是?c) -
${item.rate?is_number?c}返回 true,即使数字前面明显有 R 的货币符号。 -
但是如果你只写
${1},它没有R?那么,我猜${item.rate?string('#.00')}也失去了R,还有${item.rate + 1}。可以?我只是想知道他们是如何实现这一点的。使用TemplateNumberFormat是可行的,但他们不妨修改 FreeMarker...AFAK 他们有自己的封闭源代码分支。
标签: netsuite freemarker