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

SuiteScript:Suitelet子列表“Refresh按钮”功能及触发动作问询

Suitelet子列表中“Refresh(刷新)”按钮的功能逻辑与触发操作详解

Hey folks, let's dive into exactly how the Refresh button works when you're working with sublists in a Suitelet. I've helped a lot of developers wrap their heads around this, so I'll break it down clearly—no jargon overload, promise.

一、核心功能逻辑

At its core, the Refresh button is all about updating just the sublist with fresh data without reloading the entire Suitelet page. Here's the key logic:

  • It targets only the specific sublist it's attached to, not the whole form. So any other fields, dropdowns, or input values you've already filled out on the Suitelet stay exactly as they are.
  • It re-runs the data-fetching logic tied to the sublist. Whether you're pulling data from a saved search, a custom record, or dynamic calculations, clicking Refresh tells NetSuite to grab the latest version of that data and re-render the sublist rows.

二、点击按钮后触发的具体操作(客户端/服务端拆分)

Let's split this into what happens on the front-end (client side) and back-end (NetSuite server/SuiteScript):

客户端(页面层面)操作

  • First, you'll see a small loading animation in the sublist area—this tells you NetSuite is fetching new data.
  • The existing rows in the sublist get cleared out immediately.
  • Once the server sends back fresh data, the sublist gets repopulated with the new rows.
  • By default, any custom sorting or pagination you had applied to the sublist will reset to the default state (first page, default sort order), unless you've built custom logic to preserve those settings.

服务端(SuiteScript层面)操作

This depends on whether you're using SuiteScript 1.x or 2.x, but the core idea is the same:

SuiteScript 2.x

  • If you defined a refreshFunction for your sublist (like in the code example below), clicking Refresh triggers that specific function. This lets you customize exactly how the sublist data is refreshed (e.g., applying filters from other form fields).
  • If you didn't set a custom refreshFunction, NetSuite will default to re-running the original data-population logic you wrote when creating the sublist—so it'll re-fetch the data source (like a saved search) and rebuild the sublist rows.

SuiteScript 1.x

  • The button triggers a call back to your Suitelet's onRequest method, specifically re-executing the code block that generates and populates the sublist. It then sends the updated sublist HTML back to the client to render.

快速代码示例(SuiteScript 2.x)

Here's a simplified snippet to show how you might tie a custom refresh function to a sublist:

define(['N/ui/serverWidget', 'N/search'], function(serverWidget, search) {
    function onRequest(context) {
        if (context.request.method === 'GET') {
            var form = serverWidget.createForm({title: 'Inventory Sublist Demo'});
            
            // 创建带自定义刷新函数的子列表
            var invSublist = form.createSublist({
                id: 'custpage_inventory',
                type: serverWidget.SublistType.LIST,
                label: 'Current Inventory'
            });
            invSublist.addField({
                id: 'custpage_item_name',
                type: serverWidget.FieldType.TEXT,
                label: 'Item Name'
            });
            invSublist.addField({
                id: 'custpage_qty',
                type: serverWidget.FieldType.INTEGER,
                label: 'Quantity'
            });
            // 绑定自定义刷新函数
            invSublist.refreshFunction = 'refreshInventorySublist';
            
            // 填充初始数据
            loadInventoryData(invSublist);
            
            context.response.writePage(form);
        } else {
            // 处理刷新的POST请求
            if (context.request.parameters.refreshInventorySublist) {
                var sublist = serverWidget.createSublist({
                    id: 'custpage_inventory',
                    type: serverWidget.SublistType.LIST,
                    label: 'Current Inventory'
                });
                // 重新获取最新库存数据
                loadInventoryData(sublist);
                context.response.write(sublist.toHtml());
            }
        }
    }
    
    function loadInventoryData(sublist) {
        // 通过搜索获取最新库存数据
        var invSearch = search.create({
            type: search.Type.INVENTORY_ITEM,
            columns: ['name', 'quantityonhand']
        });
        var results = invSearch.run().getRange({start: 0, end: 10});
        
        for (var i = 0; i < results.length; i++) {
            sublist.setSublistValue({
                id: 'custpage_item_name',
                line: i,
                value: results[i].getValue('name')
            });
            sublist.setSublistValue({
                id: 'custpage_qty',
                line: i,
                value: results[i].getValue('quantityonhand')
            });
        }
    }
    
    return {
        onRequest: onRequest
    };
});

In this example, clicking Refresh triggers the refreshInventorySublist function, which re-runs the inventory search to get the latest stock counts and updates the sublist without touching other parts of the form.


内容的提问来源于stack exchange,提问作者Steve Reeder

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.12 04:21:11