Search Filter Creation with SuiteScript Parameters
Create custom search filters in SuiteScript using parameters for efficient data retrieval and manipulation.
Creating a search filter in SuiteScript allows developers to refine and manipulate data retrieval effectively. This article discusses parameters used to create search filters with the N/search module, the required fields, and the structure of the code needed.
What Are Search Filters?
Search filters are vital components in SuiteScript that help define specific criteria for data retrieval. You can create a new search filter as a search.Filter object in your SuiteScripts.
Important Considerations
When creating filters for list or record type fields using SuiteScript:
- Field Identification: You should always use the field's internal ID instead of its text value. If necessary, use a formula with
name: 'formulatext'.
Supported Script Types
Search filters can be utilized in both client and server scripts, providing flexibility depending on the context of your application. There is no governance limitation associated with their usage.
Parameters for Creating Search Filters
The options parameter is a JavaScript object that encapsulates all parameters necessary for creating a search filter. Here’s a breakdown of the parameters supported:
| Parameter | Type | Required / Optional | Description |
|---|---|---|---|
options.name | string | required | Name or internal ID of the search field. |
options.join | string | optional | Join ID for the search filter. |
options.operator | string | required | Operator used for the search filter. |
options.values | `string | Date | number |
options.formula | string | optional | Formula used by the search filter. |
options.summary | string | optional | Summary type for the search filter. |
Error Codes and Handling
When creating search filters, you may encounter several error codes. Here are a few common ones:
- SSS_INVALID_SRCH_OPERATOR: This error appears when an invalid operator is used in the
options.operatorparameter. - SSS_INVALID_SRCH_SUMMARY_TYP: Thrown when an invalid summary type is passed in the
options.summary. - SSS_MISSING_REQD_ARGUMENT: Indicates that a required argument is missing in the parameters.
Example Syntax for Creating a Search Filter
Below is an example of how to create a search filter in SuiteScript. Note that this code sample focuses on syntax and does not include a complete functional example:
1// Example to create a search filter2var result = search.create({3 type: 'employee',4 columns: ['firstname', 'lastname', 'role'],5 filters: [6 search.createFilter({7 name: 'iscustom',8 join: 'role',9 operator: search.Operator.IS,10 values: true11 })12 ]13}).run().getRange({14 start: 0,15 end: 10016});17log.debug({18 title: 'Result',19 details: result20});Who This Affects
This content is valuable for:
- Developers: Those involved in script writing and data manipulation within the NetSuite environment.
- Administrators: Users responsible for setting up and maintaining efficient searches in databases.
Key Takeaways
- Always use internal IDs for fields when creating filters in SuiteScript.
- Understand the parameters and their types to avoid errors in your search filters.
- Utilize the N/search module effectively to create comprehensive search definitions to streamline data retrieval.
Source: This article is based on Oracle's official NetSuite documentation.
Frequently Asked Questions (4)
Can search filters be used in both client and server SuiteScripts?
What should be used to identify fields when creating search filters in SuiteScript?
What happens if an invalid operator is used in the search filter options?
Is there a governance limitation on using search filters 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