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.

·3 min read·View Oracle Docs

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:

ParameterTypeRequired / OptionalDescription
options.namestringrequiredName or internal ID of the search field.
options.joinstringoptionalJoin ID for the search filter.
options.operatorstringrequiredOperator for the search filter; refer to the search.Operator enum for valid options.
options.valuesstringDatenumber
options.formulastringoptionalFormula utilized by the search filter.
options.summarystringoptionalSummary 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 the options.operator parameter is invalid or incorrectly formatted.
  • SSS_INVALID_SRCH_SUMMARY_TYP: Thrown when the options.summary parameter 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:

suitescript
1// Create a search filter joined to another record type
2var 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: true
11 })
12 ]
13}).run().getRange({
14 start: 0,
15 end: 100
16});
17log.debug({
18 title: 'Result',
19 details: result
20});

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.

Source: This article is based on Oracle's official NetSuite documentation.

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?
To filter using a field's text value in SuiteScript 2.x, you must use a formula with the parameter `name: 'formulatext'`, as direct text values cannot be used for list or record type fields.
Are search filters in SuiteScript 2.x usable in both client and server scripts?
Yes, search filters created in SuiteScript 2.x can be utilized in both client and server scripts.
What error might occur if I use an incorrect operator in a search filter?
If an incorrect operator is used in a search filter, you might encounter the `SSS_INVALID_SRCH_OPERATOR` error code.
Is it necessary to provide all parameters when creating a search filter in SuiteScript 2.x?
Not all parameters are required when creating a search filter. However, `options.name` and `options.operator` are mandatory. Other parameters such as `options.join`, `options.values`, `options.formula`, and `options.summary` are optional.
Source: Syntax Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Platform

View all Platform articles →