ANS-1288 · SUITESCRIPT DEVELOPMENT

How to Efficiently Retrieve Search Results in NetSuite SuiteScript 2.0?

NetSuite SuiteScript 2.0 offers three distinct methods for retrieving search results, each with unique performance and use-case considerations.

Short answer

SuiteScript 2.0 provides three primary methods for retrieving search results: `search.ResultSet.getRange()`, `search.ResultSet.each()`, and `search.PagedData.fetch()`. Each method offers different benefits regarding metering units, result limits, and ease of use, making the choice dependent on specific script requirements and the volume of data.

Scenario

Developers working with NetSuite SuiteScript 2.0 often need to retrieve data from saved searches or dynamically created searches. The challenge lies in selecting the most appropriate method for result retrieval, considering factors such as the total number of expected results, script governance limits, and desired performance efficiency. Choosing the wrong method can lead to script errors, excessive metering unit consumption, or inefficient data processing.

Solution

SuiteScript 2.0 provides three distinct methods for retrieving search results, each suited for different scenarios based on performance, metering, and result volume. The optimal choice depends on the specific requirements of the script.

search.ResultSet.getRange()

This method allows for the retrieval of a specific slice of results, supporting up to 1000 results per execution at a cost of 10 metering units per run.

Pros:

  • Can retrieve all results
  • Can easily return a specific subset of results (e.g., the first record)
  • Similar to 1.0 syntax used by guruSearchRecord().

Cons:

  • Most metering heavy (10 units per 1000 results)

search.ResultSet.each()

This method facilitates easy iteration over search results and can retrieve up to 4000 results in one execution.

Pros:

  • Only 10 metering units to retrieve up to 4000 results (lowest metering)
  • Clean and simple code (no need to handle retrieving all results)

Cons:

  • Can only retrieve 4000 results (at the 4001 result it will throw an error!).

search.PagedData.fetch()

This method closely mimics the way search results are presented in the user interface and allows page sizes up to 1000 results.

Pros:

  • Most metering efficient when retrieving more than 4000 records (5 units + 5 units per 1000 results)
  • Allows users to see how many results there are without retrieving everything.
  • Includes key->value data that can be easily used for a pagination drop-down.

Cons:

  • Slightly more complicated to use than the other two methods.

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant