You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在NetSuite高级PDF模板中分组Club Type并排序其子类型?

NetSuite高级PDF模板:按Club Type分组并排序Club Sub Type

问题场景

当前生成销售订单PDF时,Club Type与Club Sub Type的输出为:

Club TypeClub Sub type
Iron5 Iron
Putter6 Putter
WoodWood 5
WedgeWedge 2
Iron9 Iron
WoodWood 1
WedgeWedge 5

需要实现按Club Type分组,且每组内的Club Sub Type按升序排列,期望输出:

Iron – 5 Iron, 9 Iron
Putter – 6 Putter
Wedge – Wedge 2, Wedge 5
Wood – Wood 1, Wood 5

现有商品表格代码:

<table style="width: 100%; margin-top: 10px;">
<!-- start items -->
<#list record.item as item>
<#if item_index==0>
<thead>
<tr>
<th>Qty</th>
<th>ITEM</th>
<th>CLUB<br/>TYPE</th>
<th>CLUB<br/>SUB<br/>TYPE</th>
<th>HEAD</th>
<th>SHAFT</th>
<th>GRIP</th>
</tr>
</thead>
</#if>
<tr>
<td>${record.item.quantity}</td>
<td>${item.item}</td>
<td>${item.custcol_cc_clubtype_so}</td>
<td>${item.custcol_cc_club_subtype_so}</td>
<td>${item.custcol_cc_head_description_so}</td>
<td>${item.custcol_cc_shaft_description_so}</td>
<td>${item.custcol_cc_grip_description_so}</td>
</tr>
</#list>
<!-- end items -->
</table>

解决方案

NetSuite高级PDF基于FreeMarker模板引擎,通过以下代码实现分组排序:

分组排序实现代码

将以下代码插入到模板的合适位置(如原有商品表格下方,或替换原有表格块):

<!-- 按Club Type分组并排序Sub Type -->
<#assign groupedItems = record.item?group_by("custcol_cc_clubtype_so")>
<#list groupedItems?keys?sort as clubType>
    <#assign sortedSubTypes = groupedItems[clubType]?sort_by("custcol_cc_club_subtype_so")>
    <#assign subTypeStr = sortedSubTypes?map("custcol_cc_club_subtype_so")?join(", ")>
    ${clubType} – ${subTypeStr}<br/>
</#list>

代码逻辑说明

  • ?group_by("custcol_cc_clubtype_so"):将商品列表按Club Type字段分组,生成键为Club Type、值为对应商品集合的哈希结构
  • ?keys?sort:对分组后的Club Type进行升序排序,保证输出顺序符合示例要求
  • ?sort_by("custcol_cc_club_subtype_so"):对每组内的商品按Sub Type字段升序排列
  • ?map("custcol_cc_club_subtype_so")?join(", "):提取每组的所有Sub Type值,用逗号拼接成字符串

若需保留原有商品表格,仅新增分组汇总展示,直接将上述代码插入到模板的对应位置即可。

内容的提问来源于stack exchange,提问作者Maira S

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 12:35:14