SuiteScript Saved Search Unlimited Results

in , , December 22nd, 2023

Why Fetch 4000+ Saved Search Results

When you are trying to create a saved search in NetSuite, sometimes there is reason to be worried about the result count going beyond the 4000 limit that searchObj.run().each() imposes. If you think your saved search could return more results than the 4000 allowed, it may make sense to bypass this limit with the alternative code provided below. Ensuring that you can fetch all the results with your saved search provides you with confidence in the integrity of the resulting data as you process, work with, and report on it.

How to Bypass the Saved Search Result Limit

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);
  });
});

A Note on Saved Search Result Count Impact

When using the code provided above to eliminate the 4000 result limit of a saved search, it is important that you be wary of the governance and performance impact of running searches on 4000+ results. Even in cases where fetching 4000+ results has obvious benefits, you will want to consider whether there is a negative impact that will outweigh what you are gaining.

Author: Steve Linn


Got stuck in a step during this article?

That's all for now! We like to update our blogs and articles to make sure they help resolve any troubleshooting difficulties you are having. Sometimes there is a related feature to enable or a field to fill out that we miss during the instructions. If this article didn't resolve the issue, please use the chat and let us know so that we can update this article!

 
 

Want to keep learning?

Our team of NetSuite professionals has written articles on a wide variety of NetSuite topics, from SuiteCommerce tips, to recommended NetSuite solutions, to available support services, and more! 

Your cart