Load and Run a Paginated Search and Process the Results

The following sample loads and runs a saved search for sales order records. The sample uses the forEach callback function to process the paginated results.

Note:

This sample script uses the require function so that you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.1 Script Basics and SuiteScript 2.1 Script Types.

          /**
 * @NApiVersion 2.1
 */
require(['N/search'], (search) => {
    const loadAndRunSearch = () => {
        const mySearch = search.load({
            id: 'customsearch_my_so_search'
        });

        const pagedData = mySearch.runPaged();

        pagedData.pageRanges.forEach((pageRange) => {
            const page = pagedData.fetch({
                index: pageRange.index
            });

            page.data.forEach((result) => {
                const entity = result.getValue({ name: 'entity' });
                const subsidiary = result.getValue({ name: 'subsidiary' });

                log.debug({
                    title: 'Sales order result',
                    details: { entity, subsidiary }
                });
            });
        });
    };

    loadAndRunSearch();
}); 

        

General Notices