Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
492 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...