【问题标题】:How to add checkbox in a list (serverWidget.List) in Suitelet如何在 Suitelet 的列表 (serverWidget.List) 中添加复选框
【发布时间】:2019-03-13 18:29:08
【问题描述】:

我刚开始使用 NetSuite 和 SuiteScript 2.0。这是我的需要:

我需要根据记录创建一个列表,然后我需要在列表中选择所需的行以仅对选定的行调用函数。

目前,我创建了一个列表(使用 N/ui/serverWidget.List 对象),我可以使用 N/search 模块显示我的记录中的行来提供我的列表,我还在列出,以便我可以调用一个函数。

我卡住的地方是选择列表中出现的行,以便仅触发所选行的功能。

使用 API,我尝试为列表添加一个 CHECKBOX 类型的列,但它不起作用。

您知道实现这一目标的最佳方法吗?

谢谢。

【问题讨论】:

    标签: netsuite suitescript2.0


    【解决方案1】:

    这是一个使用 Suitelet 将复选框添加到子列表的示例。您可以在客户端脚本中通过循环遍历这些行并检查该字段是否为真来处理它们。

    function onRequest(context) {
            // Create the form
            function createForm() {
                try {
                    var form = serverWidget.createForm({
                        title: 'My Form',
                        hideNavBar: false
                    });
                    // In the client script, handle the checked lines by looping over the
                    // custpage_table sublist and looking to see if custpage_wo_process is true
                    form.clientScriptModulePath = 'SomeScript.js';
                    form.addButton({
                        id: 'custpage_myaction',
                        label: 'Process',
                        functionName: 'printRecords'
                    });
                    // Add a sublist to the form
                    var sublist = form.addSublist({
                        id: 'custpage_table',
                        type: serverWidget.SublistType.LIST,
                        label: 'Records to Process'
                    });
                    // Show a 'Mark All' button
                    sublist.addMarkAllButtons();
                    // Add an internalid to track the line item
                    var idField = sublist.addField({
                        id: 'custpage_rec_id',
                        label: 'Internal ID',
                        type: serverWidget.FieldType.TEXT
                    });
                    idField.updateDisplayType({
                        displayType: serverWidget.FieldDisplayType.HIDDEN
                    });
                    // Add a checkbox to mark which records should be processed
                    var printField = sublist.addField({
                        id: 'custpage_rec_process',
                        label: 'Process',
                        type: serverWidget.FieldType.CHECKBOX
                    });
                    // return the form and sublist
                    return {form: form, sublist: sublist};
                } catch (e) {
                    log.error('Error creating form.', e);
                }
            }
    
            function handleGet() {
                var myForm = createForm();
                if (myForm) {
                    // Get the form
                    var form = myForm.form;
                    // Get the sublist
                    var sublist = myForm.sublist;
                    // Do a search, etc to get the records to add to the sublist
                    var addResults = fetchSearchResult();
                    // Add the values to the sublist
                    for (var i = 0; i < addResults.length; i++) {
                        sublist.setSublistValue({
                            id: 'custpage_rec_id',
                            line: i,
                            value: addResults[i].id
                        });
                    }
                    context.response.writePage(form);
                }
            }
    
            if (context.request.method === 'GET') {
                handleGet();
            }
        }
    

    【讨论】:

    • 谢谢!这正是我的需要。 serverWidget.List 对象没有提供很多可能性,serverWidget.Sublist 对象带来了更多。它们被命名为 List 和 Sublist 的事实非常令人困惑,因为您可以将 Sublist 对象用作顶级列表。
    猜你喜欢
    • 2011-05-12
    • 2023-04-10
    • 2014-03-03
    • 1970-01-01
    • 1970-01-01
    • 2013-03-10
    • 1970-01-01
    • 2012-05-20
    • 1970-01-01
    相关资源
    最近更新 更多