SuiteScript Saved Search Unlimited Results

Context

You are trying to create a saved search in NetSuite and are worried about the result count going beyond the 4000 limit that searchObj.run().each() imposes.

Wisdom

Instead of running searchObj.run().each(), use the following:

const mySearch = '(search loaded or created)'; // replace with N_search.load() or N_search.create() as appropriate

const pagedData = mySearch.runPaged({
    pageSize: 1000
});

const results = [];

pagedData.pageRanges.forEach(function (pageRange) {
    const page = pagedData.fetch({ index: pageRange.index });
    page.data.forEach(function (result) {
        // Do something with the result. In this case, add it to the results array.
        results.push(result);
    });
});

Be wary of governance and performance impact of running searches on 4000+ results

Leave a comment

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