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


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

1

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