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

NetSuite自定义表单:嵌套FreeMarker表格分页失效求助

解决NetSuite FreeMarker分组后分页失效问题

问题描述

在NetSuite自定义表单中用FreeMarker遍历记录,已实现按Billing Class分组,但分页逻辑不生效,<pbr></pbr>标签无法触发分页。

问题根源

  1. 原代码仅统计数据行,未将分组标题行计入行数,导致分页触发时机错误
  2. NetSuite渲染引擎认可的分页标签是单标签<pbr/>,而非双标签<pbr></pbr>
  3. 分页后未重新生成表头,新页面缺少完整表头结构
  4. 分页触发条件判断有漏洞,可能导致分组被拆分到跨页时显示异常

修复后的完整代码

<table style="width: 100%; border: 0px;">
<tr>
<td align="center">
    <p><strong style="font-size: 10;">foo bar, LLC</strong></p>
    <p><strong style="font-size: 12;">Time by Job Detail</strong></p>
    <p><strong style="font-size: 12;">${record.job}</strong></p>
    <hr class="thick-hr" />
    <#-- 定义表头模板,方便分页复用 -->
    <#macro tableHeader>
        <table>
            <tr>
                <td class="underline-container"><span class="underline">Date</span></td>
                <td class="underline-container"><span class="underline">Name</span></td>
                <td class="underline-container"><span class="underline">Billing Status</span></td>
                <td class="underline-container"><span class="underline">Duration</span></td>
            </tr>
    </#macro>

    <#-- 初始化变量 -->
    <#assign billingClasses = [] />
    <#list record.item as timeEntry>
        <#if !billingClasses?seq_contains(timeEntry.item)>
            <#assign billingClasses += [timeEntry.item] />
        </#if>
    </#list>
    <#assign rowsPerPage = 30 />
    <#assign rowCount = 0 />
    <#assign totalDuration = 0 />

    <#-- 渲染初始表头 -->
    <@tableHeader />

    <#-- 遍历每个Billing Class分组 -->
    <#list billingClasses as billingClass>
        <#-- 先检查当前分组标题+数据行是否会超出分页限制 -->
        <#assign groupRowCount = 1 + record.item?filter(it -> it.item == billingClass)?size />
        <#if rowCount + groupRowCount > rowsPerPage>
            <#-- 先关闭当前表格,插入分页标签,再重新渲染表头和分组标题 -->
            </table><pbr/><@tableHeader />
            <tr>
                <td colspan="4" style="font-weight: bold; text-align: left;">${billingClass}</td>
            </tr>
            <#assign rowCount = 1 /> <!-- 重置行数,已计入分组标题行 -->
        <#else>
            <#-- 正常渲染分组标题 -->
            <tr>
                <td colspan="4" style="font-weight: bold; text-align: left;">${billingClass}</td>
            </tr>
            <#assign rowCount = rowCount + 1 /> <!-- 分组标题行计入行数 -->
        </#if>

        <#-- 遍历当前分组下的条目 -->
        <#list record.item?filter(it -> it.item == billingClass) as timeEntry>
            <#if rowCount >= rowsPerPage>
                <#-- 触发分页 -->
                </table><pbr/><@tableHeader />
                <tr>
                    <td colspan="4" style="font-weight: bold; text-align: left;">${billingClass}</td>
                </tr>
                <#assign rowCount = 1 /> <!-- 重置行数,已计入分组标题行 -->
            </#if>

            <tr>
                <td>${timeEntry.billeddate}</td>
                <td>${timeEntry.employeefullname}</td>
                <td>${timeEntry.item}</td>
                <td>${timeEntry.quantity}</td>
            </tr>
            <#assign totalDuration += timeEntry.quantity />
            <#assign rowCount = rowCount + 1 /> <!-- 数据行计入行数 -->
        </#list>
    </#list>

        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td style="text-align: right; font-weight: bold;">Total:</td>
            <td style="font-weight: bold;">${totalDuration}</td>
        </tr>
    </table>
</td>
</tr>
</table>

关键修改说明

  • 复用表头模板:用<#macro>定义表头,分页后可直接调用,保证每个页面都有完整表头
  • 修正分页标签:将<pbr></pbr>替换为NetSuite认可的<pbr/>单标签
  • 完整行数统计:把分组标题行也计入rowCount,避免分页时机偏差
  • 分组跨页预判:提前计算当前分组的总行数(标题+数据),如果加上当前已用行数超过每页限制,先分页再渲染分组,避免分组被拆分到跨页
  • 优化分页触发逻辑:在渲染每一行数据前检查是否达到分页限制,确保分页位置准确

内容的提问来源于stack exchange,提问作者Joel Porter

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 15:43:09