how to Suitelet SuiteScript 2.0 to Show Results of...
# ask-stanley-ai
n
how to Suitelet SuiteScript 2.0 to Show Results of Saved Search on Multiple Pages
c
AI generated answer (using internal Slack threads):
To show the results of a saved search on multiple pages using Suitelet SuiteScript 2.0, you can use the
N/search
module to load and run the saved search, and then use the
N/ui/serverWidget
module to create a sublist to display the results. Here's a basic example of how you might do this:
Copy code
javascript
/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 */
define(['N/search', 'N/ui/serverWidget'], function(search, serverWidget) {
    function onRequest(context) {
        if (context.request.method === 'GET') {
            var form = serverWidget.createForm({
                title: 'Saved Search Results'
            });

            var sublist = form.addSublist({
                id: 'results',
                type: serverWidget.SublistType.LIST,
                label: 'Results'
            });

            // Add your columns here
            sublist.addField({
                id: 'field1',
                type: serverWidget.FieldType.TEXT,
                label: 'Field 1'
            });

            var mySearch = search.load({
                id: 'customsearch_my_saved_search'
            });

            var pagedData = mySearch.runPaged({
                pageSize: 100
            });

            pagedData.pageRanges.forEach(function(pageRange) {
                var myPage = pagedData.fetch({ index: pageRange.index });
                myPage.data.forEach(function(result) {
                    sublist.setSublistValue({
                        id: 'field1',
                        line: sublist.lineCount,
                        value: result.getValue({ name: 'field1' })
                    });
                });
            });

            context.response.writePage(form);
        }
    }

    return {
        onRequest: onRequest
    };
});
This script creates a Suitelet that displays a form with a sublist. The sublist is populated with the results of a saved search. The
runPaged
method is used to handle large result sets by breaking them up into pages. Each page of results is fetched and added to the sublist. Please replace
'customsearch_my_saved_search'
with the ID of your saved search, and adjust the field definitions and
getValue
calls to match the columns in your saved search. Remember, this is a basic example and you might need to adjust it to fit your specific needs. For example, you might want to add pagination controls to navigate between pages of results, or add filters to limit the results displayed.
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.858506441
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.854471564
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.852301121
Please provide your feedback on this answer.