How to add checkbox in a list (serverWidget.List) in Suitelet

混江龙づ霸主 提交于 2020-02-08 11:21:04

问题


I just started using NetSuite and SuiteScript 2.0. Here is my need:

I need to create a list based on a record, then I need to select the desired lines on the list to call a function only for the selected lines.

Currently, I created a list (using N/ui/serverWidget.List object), and I'm able to display the lines from my record using N/search module to feed my list, I also created a button on the list so I can call a function.

Where I'm stuck, it's to select the lines that appear in the list in order to trigger a function only for the selected lines.

With the API, I tried to add a column of type CHECKBOX for the list but it doesn't work.

Do you know the best way to achieve that?

Thank you.


回答1:


Here is an example using a Suitelet to add the checkbox to the sublist. You'd handle them in your client script by looping over the lines and checking to see if the field is true.

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


来源:https://stackoverflow.com/questions/55148957/how-to-add-checkbox-in-a-list-serverwidget-list-in-suitelet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!