ResultSet Object in SuiteScript: Working with Search Results

The ResultSet object in SuiteScript allows developers to manage, iterate, and access search results up to 4000 records.

·2 min read·View Oracle Docs

The ResultSet object encapsulates a collection of search results returned by the Search.run() method. This object is crucial for developers working with SuiteScript as it facilitates effective iteration and retrieval of search results. A key limitation to note is that a ResultSet can hold a maximum of 4000 results; for searches exceeding this number, you must use Search.runPaged() or Search.runPaged.promise() to access the complete result set.

Important Considerations

  • Non-Caching: Result sets are not cached. If records relevant to your search are added, modified, or deleted during your interaction with the ResultSet, the results may change dynamically.
  • Text Column Limits: Text columns in search results are constrained to a maximum of 4000 bytes. This limit is significant when dealing with character sets that may require more than one byte per character, thus potentially decreasing the effective character limit.

Supported Script Types

You can use the ResultSet in both client and server scripts, providing flexibility depending on your development needs.

Module

The ResultSet belongs to the N/search module, which is essential for executing searches in SuiteScript.

Methods and Properties

The ResultSet object supports various methods and properties that allow you to iterate through search results effectively. Major members include:

Method/PropertyTypeDescription
each(callback)MethodExecutes a callback function for each search result.
getValue(options)MethodRetrieves the value of a specified search result column.

Code Sample

Below is an example demonstrating how to utilize the ResultSet object to load and run a saved search:

suitescript
1// Load a saved search
2var mySearch = search.load({
3 id: 'customsearch_my_cs_search'
4});
5
6// Execute search and process each result
7mySearch.run().each(function(result) {
8 var entity = result.getValue({ name: 'entityid' });
9 log.debug(entity);
10
11 var email = result.getValue({ name: 'email' });
12 log.debug(email);
13
14 return true; // Return true to continue iteration
15});

Who This Affects

  • Developers: Anyone building scripts that leverage search functionalities in NetSuite can benefit from understanding and using the ResultSet object effectively.
  • Administrators: Those managing or configuring saved searches may find this information useful when guiding developers or troubleshooting issues.

Key Takeaways

  • The ResultSet object allows handling up to 4000 search results.
  • Searches executed dynamically are not cached, affecting real-time data interaction.
  • Use Search.runPaged() for result sets exceeding 4000 entries.
  • Ensure to consider text limits in search columns due to varying byte sizes.

Source: This article is based on Oracle's official NetSuite documentation.

Frequently Asked Questions (4)

When should I use Search.runPaged() instead of ResultSet?
You should use Search.runPaged() when your search results exceed 4000 records as the ResultSet object can only manage up to 4000 records.
Can I use the ResultSet object for both client and server-side scripts in SuiteScript?
Yes, the ResultSet object is supported in both client and server scripts, providing flexibility depending on your development needs.
Does the ResultSet object cache the search results?
No, the ResultSet object does not cache search results. If records relevant to your search change during your interaction, the results may change dynamically.
Are there limitations on the text column data within a ResultSet object?
Yes, text columns in search results are constrained to 4000 bytes, which is significant when dealing with character sets that require more than one byte per character.
Source: Syntax Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Searches

View all Searches articles →