NetSuite Save Search Pagination

NetSuite is a cloud-based enterprise resource planning (ERP) software that offers a range of tools and features for managing business operations and data. One of the features of NetSuite is the ability to create saved searches. This allows users to define specific criteria for searching and filtering their data, and then save those criteria for future use. 

Pagination is a process of splitting a large number of saved search results into chunks (pages) in order to process them more efficiently, in line with SuiteScript governance limits. To paginate the results of a saved search in NetSuite, users can use the ‘search.create.setPaging’ function. This function takes two arguments: the page index (an integer starting at 0) and the page size (the number of results to return per page). 

This blog highlights how users can run a search in the script and access large data sets without any governance errors. 

When a user runs a search in the script, they use API 

 search.run().getRange({ start : 0, end: 1000});  

to get only 1000 results.  

Let’s consider a scenario where a developer is working on an integration and is expecting to retrieve 100’000 + lines of data from NetSuite. In this scenario, our developer must consider Saved Search and platform limitations, including the back-end system data governance. 

First, the user needs to write a script , it may be a user event, client script, map Reduce, RestLet. Now with the help of the search module, the user can create/load the search in their code.

Next, the developer will call ‘Search.run()’ method. They must not forget to add ‘start’ and ‘end’ variables as demonstrated below: 

Var startIndex = 0; Var RANGECOUNT = 1000; 

Modify the standard behavior of search.run() with logic as explained below: 

saved search ID

Load a search that we can export according to the situation explained above. Here we declare and initiate two variables startIndex and RANGECOUNT, and initiate. Next run search in the do while looping and using these variables instead of giving an integers value.  

In the very next line, CONCATE results and push into another array allResults (array), and in the next line overwrite startIndex with pagedResultCount right now which is 1000 NOW our startIndex variable is 1000 instead of 0.  

Now we need the next page results and push them into the same array until pagedResultsCount == RAGECOUNT and loop is running until all save search results are not pushed into allResults (array). 

LASTLY, when looking at the logs, you can see all search results are pushed into a single array and you can use it according to your situation. 

Conclusion 

With Search Pagination you can run a search without any limitation error and no matter what the range of results, they are automatically handled and pushed into your array. Â