Search Filters Creation in SuiteScript 2.x for NetSuite
Search filters can be created in SuiteScript 2.x to refine data efficiently. This guide outlines syntax and parameters.
Creating search filters in SuiteScript 2.x allows you to enhance data retrieval based on specified criteria. Understanding the correct syntax and method parameters is essential for effective use.
How Do Search Filters Work?
In SuiteScript 2.x, a search filter is created as an object using the search.Filter functionalities. Here’s an important note: you cannot use a field's text value directly to create a filter for a list or record type field. Instead, you must use the field's internal ID. If you absolutely need to filter using the text value, you can create a filter or column by employing a formula with name: 'formulatext'.
Return Value
The method returns a search.Filter object, which can be utilized within your search definitions.
Supported Script Types
Search filters can be leveraged in both client and server scripts. For detailed information about SuiteScript 2.x script types, refer to the relevant documentation.
Parameters for Filter Creation
When creating a filter, an options parameter, structured as a JavaScript object, is essential. It includes the following:
| 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 for the search filter; refer to the search.Operator enum for valid options. |
options.values | string | Date | number |
options.formula | string | optional | Formula utilized by the search filter. |
options.summary | string | optional | Summary type for the search filter. See search.Summary documentation for more details. |
Error Handling
When working with search filters, you might encounter the following error codes:
SSS_INVALID_SRCH_OPERATOR: This error is reported when theoptions.operatorparameter is invalid or incorrectly formatted.SSS_INVALID_SRCH_SUMMARY_TYP: Thrown when theoptions.summaryparameter has an incorrect summary type.SSS_MISSING_REQD_ARGUMENT: Signifies a missing required argument in the filter options.
Example Code Sample
The following code demonstrates how you can define and apply a search filter:
1// Create a search filter joined to another record type2var 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});Additional Considerations
If setting filter conditions on fields with Long Text or Rich Text types, keep in mind that there's a character limit of approximately 500 characters for matching string length, which can vary based on character encoding used.
Key Takeaways
- Search filters in SuiteScript 2.x enhance data retrieval.
- Always use the internal ID for field names in filters.
- Error handling is crucial for successful search filter usage.
- Various parameters control how filters are constructed and applied.
- Code samples illustrate practical use cases for creating filters.
Frequently Asked Questions (4)
How can I create a search filter using a field's text value in SuiteScript 2.x?
Are search filters in SuiteScript 2.x usable in both client and server scripts?
What error might occur if I use an incorrect operator in a search filter?
Is it necessary to provide all parameters when creating a search filter in SuiteScript 2.x?
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.
- PagedData Object Members in NetSuite SuiteScript 2.0
PagedData provides efficient pagination for search results in SuiteScript, enabling effective handling of large data sets.
- Search Object Errors in SuiteScript for NetSuite
Understand common search object errors in SuiteScript for NetSuite and how to resolve them effectively.
- Search Filter Object Usage in SuiteScript
The Search Filter object enables refined query capabilities in SuiteScript, encapsulating search criteria.
Advertising
Reach Searches Professionals
Put your product in front of NetSuite experts who work with Searches every day.
Sponsor This Category