如何在Suitelet

时间:2019-03-13 18:29:09

标签: netsuite suitescript2.0

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

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

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

在我停留的地方,是选择列表中出现的行,以便仅针对所选行触发功能。

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

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

谢谢。

1 个答案:

答案 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();
        }
    }