Implementing Select All and Unselect All Functionality in Suitelet

In Suitelet scripts, managing sublist items through “Select All” and “Unselect All” buttons can significantly enhance user experience by providing quick options to select or deselect multiple items. Here, we will walk through the process of adding these buttons to a Suitelet sublist and handling their functionality using a client script.

Suitelet Script Snippet

// Add "Select All" button to the sublist
sublist.addButton({
    id: 'custpage_select_all',
    label: 'Select All',
    functionName: 'selectAll("select")'
});

// Add "Unselect All" button to the sublist
sublist.addButton({
    id: 'custpage_unselect_all',
    label: 'Unselect All',
    functionName: 'selectAll("unselect")'
});

Client Script Snippet

// Client script for handling "Select All" and "Unselect All" functionality
/**
 * @NApiVersion 2.1
 * @NScriptType ClientScript
 */
define(['N/currentRecord'], function(currentRecord) {
    function selectAll(status) {
        let recordObj = currentRecord.get();
        let lineCount = recordObj.getLineCount({ sublistId: 'custpage_gst_sublist' });

        for (let i = 0; i < lineCount; i++) {
            recordObj.selectLine({ sublistId: 'custpage_gst_sublist', line: i });
            recordObj.setCurrentSublistValue({
                sublistId: 'custpage_gst_sublist',
                fieldId: 'custpage_select',
                value: status === "select",
                ignoreFieldChange: true
            });
            recordObj.commitLine({ sublistId: 'custpage_gst_sublist' });
        }
    }

    return { selectAll: selectAll };
});

Explanation

  • Suitelet Script Snippet: Adds two buttons (“Select All” and “Unselect All”) to a sublist (sublist) in a Suitelet form (form). Each button calls the selectAll function in the client script with different arguments (“select” or “unselect”).
  • Client Script Snippet: Defines the selectAll function in a client script (ClientScript) that handles the “Select All” and “Unselect All” functionality. It retrieves the current record (currentRecord) object and iterates through each line of the specified sublist (custpage_gst_sublist). For each line, it sets the checkbox field (custpage_select) based on the status argument (“select” or “unselect”) and commits the changes.

These snippets demonstrate how to implement basic bulk selection functionality in a Suitelet sublist using SuiteScript 2.1. Adjust field IDs (custpage_gst_sublist, custpage_select) and sublist IDs (custpage_gst_sublist) as per your specific Suitelet configuration.

Leave a comment

Your email address will not be published. Required fields are marked *