Nour Khaled
04/29/2025, 3:40 PMCeligo AI
04/29/2025, 3:40 PMAI generated answer (using internal Slack threads):The 4000 results limit is a restriction imposed by NetSuite for the
.each() method. However, there are ways to work around this limitation. 
One way is to use the getRange() method instead of .each(). The getRange() method allows you to specify a range of results to return, so you can use it in a loop to retrieve all results in chunks. Here is an example:
javascript
function searchAll(resultsetCurrent) {
    var allResults = [];
    var startIndex = 0;
    var RANGECOUNT = 1000;
    do {
        var pagedResults = resultsetCurrent.getRange({
            start: parseInt(startIndex),
            end: parseInt(startIndex + RANGECOUNT),
        });
        allResults = allResults.concat(pagedResults);
        var pagedResultsCount = pagedResults != null ? pagedResults.length : 0;
        startIndex += pagedResultsCount;
        var remainingUsage = runtime.getCurrentScript().getRemainingUsage();
        log.debug(remainingUsage);
    } while (pagedResultsCount == RANGECOUNT);
    var remainingUsage = runtime.getCurrentScript().getRemainingUsage();
    return allResults;
}
Another approach is to use a library like NFT (NetSuite Fast Track) which provides a lazy processing model. This allows you to process all results until either completion or governance is exhausted. Here is an example:
javascript
Seq(LazySearch.load(searchid))
    .takeWhile(governanceRemains())
    .map(nsSearchResult2obj())
    .forEach(r => loadAndCloseRMA(r))
In this example, RMA ids are taken from a saved search and 'closed'. The processing is 'lazy' in the sense that no matter how many steps you chain together, no intermediate collections are created.
******
Disclaimer:
This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes.
******Celigo AI
04/29/2025, 3:41 PMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.850546479
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.840056658
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.838746369
Celigo AI
04/29/2025, 3:41 PM