NetSuite provides us with the N/query and N/search modules to interact with these analytics features from our SuiteScript.
GOVERNANCE USAGE
- For single-page result sets (less than 4000 for N/search and less than 5000 for N/query), the Governance usage of the two APIs is identical (a meager 10 units).
- For larger, multi-page result sets, N/query will use double that of N/search for the same amount of pages/results – 10 units per page for N/query as opposed to 5 for N/search.
N/SEARCH FEATURES
The N/search module provides us with the ability to interact with NetSuite’s Searching functionality (the Saved Search interface of the UI). As such, it provides all of the database querying features of that UI and more.
BODY-LEVEL LOOKUPS – One feature unique to the N/search is the lookupFields function. A very common operation in SuiteScript is to retrieve body-level data from a specific record.
DUPLICATE DETECTION SEARCH – The N/search module provides us with this same Duplicate Detection functionality via its duplicates() method. This method will run a Search with exactly the same criteria as configured in the Duplicate Detection settings for the account, helping us to identify duplicate records via SuiteScript following the company’s settings.
GLOBAL SEARCH – NetSuite’s Global Search provides users with a quick and easy way to access all kinds of data within the system with some very concise shortcut syntax for various operations. Conveniently, we can access this same functionality in SuiteScript via the N/search.global() method; the same syntax supported in the UI can be used in this SuiteScript search, allowing you to perform a Global Search in your script.
MORE CONCISE SYNTAX – The N/search module allows us to express quite complex structures through its Filter Expression syntax and its intelligent interpretation of strings to create Columns. N/query requires a series of very verbose method calls to accomplish the same thing.
N/QUERY FEATURES
MULTI-LEVEL JOINS – Workbooks and N/query support multiple levels of joins across records, as well as specific directional joins. This gives you much more flexibility and control when joining related records together in your results.
EASY OBJECT MAPPING – The N/query module has an amazing feature in its N/query.ResultSet.asMappedResults() method. asMappedResults will iterate over the Query’s ResultSet, mapping each Result instance to a plain JavaScript Object. When you define a Column on your Query, you can optionally give it an alias, and that alias will be used as the key name in the resulting Object. If you do not provide an alias, asMappedResults() will just use the Column‘s fieldId. This makes for very concise, readable result processing.
SUITEQL SUPPORT – You can write your queries directly as SQL statements instead of using all the dropdowns and drag-and-drop UI. We can leverage this same query language in SuiteScript by using the N/query.runSuiteQL() method.