【问题标题】:FreeMarker sum groupFreeMarker 和组
【发布时间】:2020-01-31 13:42:35
【问题描述】:

我正在尝试通过 NetSuite 在 Freemarker 中执行以下操作:

我在交易记录上有以下数据,即想象一个包含多行的付款记录

Doc No.   Amount
1         100
1         100
2         50
3         200
4         50
4         25
5         1000

我希望能够输出:

Doc No.       Total
1             200
2             50
3             200
4             75
5             1000

我认为您需要使用#list 和#assign 但不确定??

【问题讨论】:

  • 如果框架确实试图在模板上推送这样的计算,那就有问题了。虽然可以在 FreeMarker 中完成(因为它作为一种语言已经足够完整),但它会非常丑陋和缓慢。这不是 SQL。 NetSuite 不能改为将摘要提供给模板吗?如果没有,您不能向执行此操作的模板公开一些 Java 实用程序吗?

标签: group-by sum netsuite freemarker


【解决方案1】:

这是一个可以帮助解决这个问题的 sn-p(我希望如此)。这是从我的一个 PDF 模板中提取的,我在其中添加 locationTotal 变量。

<#list record.item as item>
  <#assign currentLocation=item.custcol_location>
    <#if currentLocation=="">
      <#assign currentLocation=record.entity>
    </#if>
    <#if item.itemtype!="Discount" && locationsProcessed?seq_index_of(currentLocation)==-1>
      <#assign locationTotal=0>
      <#list record.item as item2>
        <#assign compareLocation=item2.custcol_location>
        <#if compareLocation=="">
          <#assign compareLocation=record.entity>
        </#if>
        <#if compareLocation==currentLocation>
          <#assign locationTotal=locationTotal+item2.amount>
        </#if>
      </#list>
    <#assign newList=newList+[{"location":currentLocation,"total":locationTotal}] >
    <#assign locationsProcessed=locationsProcessed+[currentLocation] >
  </#if>
</#list>

【讨论】:

  • 嗨@W3BGUY,谢谢!但是我可以做到这一点,我得到一个错误,因为我不认为第一个位置处理(即在位置处理?seq_index_of)在使用之前被声明?不过我可能错了!
  • 是的,这只是一个如何使用列表和分配的示例。这个特殊的 freemarker 脚本大约有两千行。 :)
  • 感谢 W3BGUY,它对我的​​帮助很大!
猜你喜欢
  • 2015-04-12
  • 2015-09-24
  • 2018-12-26
  • 1970-01-01
  • 2018-04-05
  • 2012-06-25
  • 1970-01-01
  • 2010-12-11
  • 2011-03-10
相关资源
最近更新 更多