Creating and Managing Searches with SuiteScript 2.1
The search.create() method in SuiteScript enables developers to create and run searches efficiently, enhancing data retrieval processes in NetSuite.
TL;DR
The search.create(options) method in SuiteScript allows you to create new searches within the NetSuite platform, returning them as search.Search objects. This method supports various input types and allows for extensive data filtration and customization.
What is search.create(options)?
The search.create(options) method is a powerful functionality in SuiteScript that enables developers to create searches dynamically. This method can directly run searches without saving them or can save them for future use.
How Does It Work?
When implementing the search.create() method, you need to provide an options parameter, which is a JavaScript object that specifies how the search should be constructed. This method can be used as follows:
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: [{ name: 'entity' }, { name: 'subsidiary' }, { name: 'name' }, { name: 'currency' }],6 filters: [{ name: 'mainline', operator: 'is', values: ['T'] }],7 settings: [{ name: 'consolidationtype', value: 'AVERAGE' }]8});Parameters
The options object can include the following parameters:
| Parameter | Type | Required / Optional | Description |
|---|---|---|---|
options.type | search.Type | required | The search type, which specifies the context for the search. |
options.filters | search.Filter, Object, or string | optional | Accepts a single or an array of search filter objects. Supports filter expressions. |
options.filterExpression | Object[] | optional | Defines a search filter expression as an array of objects. |
options.columns | search.Column, Object | optional | Includes search column configurations. |
options.packageId | string | optional | Application ID for the search. |
options.title | string | optional | Required when saving a search for identification. |
options.id | string | optional | Automatically generated unless specified; denotes the script ID. |
options.isPublic | boolean | optional | Determines if the search is publicly accessible (default is false). |
Important Considerations
- Sorting: When defining a search, consider sorting with fields that have unique values to minimize inconsistency in search results.
- Filters: Filters for record types must use internal IDs rather than text values. However, you can utilize formulas for complex queries.
Errors
Common error codes associated with the search.create() method include:
SSS_INVALID_SRCH_COL: Invalid column type in theoptions.columnsparameter.SSS_INVALID_SRCH_FILTER_EXPR: Invalid filter expression in theoptions.filtersparameter.SSS_MISSING_REQD_ARGUMENT: Required parameters not provided.
Who This Affects
This functionality is particularly relevant for:
- Developers: Implementing custom searches and reports in SuiteScript.
- Administrators: Overseeing and managing saved searches and custom scripts in the NetSuite environment.
Key Takeaways
- The
search.create()method facilitates dynamic, on-demand search creation in SuiteScript. - Utilize unique sorting fields to ensure consistent search results.
- Be cautious with filter parameters, ensuring correct data types are provided.
Frequently Asked Questions (4)
How can I specify which records to include in a SuiteScript search?
Do I need to provide a unique 'id' when creating a search with search.create()?
Can I make a search publicly accessible when using search.create()?
What error should I be mindful of when adding columns to my SuiteScript search?
Was this article helpful?
More in Searches
- Creating Searches with SuiteScript in NetSuite
Create and manage searches in NetSuite with SuiteScript, utilizing filters, columns, and settings effectively.
- Filter Object Members for N/Search Module in NetSuite
Filter Object Members enhance search capabilities in NetSuite SuiteScript. Learn to create and configure filters effectively.
- 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.
- Error Handling in Searches with SuiteScript 2.0 Features
Gain insights into error handling in SuiteScript searches, including codes and common issues that arise when loading saved searches.
Advertising
Reach Searches Professionals
Put your product in front of NetSuite experts who work with Searches every day.
Sponsor This Category