Creating Searches with SuiteScript in NetSuite
Create and manage searches in NetSuite with SuiteScript, utilizing filters, columns, and settings effectively.
Starting with the SuiteScript API, you can create new searches that return a search.Search object. This enables you to modify, run, or save the search as per your requirements.
What is the Search Creation Method?
The search.create(options) method initializes a new search based on specified options. It is versatile, allowing for on-demand searches without saving. However, if you want to save your search for future use, simply call search.save(). The flexibility of this method allows you to utilize a variety of input formats for the options.filters argument, including a single search.Filter object or an array thereof.
Important Considerations for Search Creation
- Ensure to sort the result using fields with unique values to maintain a consistent order of results.
- Always use the internal ID of a field when creating filters or columns in SuiteScript; using text values will not work unless you use a formula.
Return Value
The method returns a search.Search object, which encapsulates the created search and its related functionality.
Supported Script Types
This method is usable in both client and server scripts.
Parameters
The options parameter is a JavaScript object with the following structure:
| Parameter | Type | Required / Optional | Description |
|---|---|---|---|
options.type | search.Type | Required | The type of search. |
options.filters | Various types including [search.Filter], array of filters, or strings | Optional | Filters for the search. |
options.columns | Various types including search.Column or array of columns | Optional | Columns to display in results. |
options.title | string | Optional | Title of the saved search. |
options.id | string | Optional | Script ID for the saved search. |
options.isPublic | boolean | Optional | Indicates if the search is public. |
Error Codes
When working with the search.create method, you may encounter the following error codes:
SSS_INVALID_SRCH_COL— Invalid column specified.SSS_INVALID_SRCH_FILTER_EXPR— Invalid filter expression provided.SSS_MISSING_REQD_ARGUMENT— A required argument is missing.
Example Usage
The following code illustrates how to create a sales order search:
1var mySalesOrderSearch = search.create({2 type: search.Type.SALES_ORDER,3 title: 'My Second SalesOrder Search',4 id: 'customsearch_my_second_so_search',5 columns: [{6 name: 'entity'7 }, {8 name: 'subsidiary'9 }, {10 name: 'name'11 }, {12 name: 'currency'13 }],14 filters: [{15 name: 'mainline',16 operator: 'is',17 values: ['T']18 }],19 settings: [{20 name: 'consolidationtype',21 value: 'AVERAGE'22 }]23});This snippet provides a skeletal structure for implementing the search creation process, while reminding you of the flexibility it offers.
Key Takeaways
- Use the
search.createmethod to initiate searches efficiently. - Always sort searches by unique field values for consistent results.
- Utilize internal field IDs when defining filters.
Source: This article is based on Oracle's official NetSuite documentation.
Frequently Asked Questions (4)
Do I need to use a unique field when sorting search results in SuiteScript?
Can I create a saved search using SuiteScript without immediately saving it?
Are there specific field identifiers that must be used when creating filters and columns in SuiteScript?
What types of scripts can use the `search.create` method in SuiteScript?
Was this article helpful?
More in Searches
- Search for Sublist Line Fields With Dynamic Tables in NetSuite
Learn how to optimize search queries for sublist line fields in NetSuite using dynamic tables and SuiteQL.
- Filter Object Members in NetSuite SuiteScript
Gain insights into the Filter Object Members of the N/search module in NetSuite SuiteScript. Learn how to create and configure filters effectively.
- Search Column Syntax for SuiteScript 2.x in NetSuite
Search column syntax in SuiteScript 2.x allows encapsulation of fields in NetSuite searches, enhancing data retrieval capabilities.
- PagedData Object Members in NetSuite SuiteScript 2.0
PagedData provides efficient pagination for search results in SuiteScript, enabling effective handling of large data sets.
Advertising
Reach Searches Professionals
Put your product in front of NetSuite experts who work with Searches every day.
Sponsor This Category