Search Filter Creation with SuiteScript Parameters

Create custom search filters in SuiteScript using parameters for efficient data retrieval and manipulation.

·3 min read·View Oracle Docs

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:

ParameterTypeRequired / OptionalDescription
options.namestringrequiredName or internal ID of the search field.
options.joinstringoptionalJoin ID for the search filter.
options.operatorstringrequiredOperator used for the search filter.
options.values`stringDatenumber
options.formulastringoptionalFormula used by the search filter.
options.summarystringoptionalSummary 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.operator parameter.
  • 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:

suitescript
1// Example to create a search filter
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});

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?
Yes, search filters can be utilized in both client and server scripts, providing flexibility depending on the application context.
What should be used to identify fields when creating search filters in SuiteScript?
You should always use the field's internal ID instead of its text value for field identification in search filters.
What happens if an invalid operator is used in the search filter options?
An invalid operator in the search filter options will result in the SSS_INVALID_SRCH_OPERATOR error.
Is there a governance limitation on using search filters in SuiteScript?
No, there is no governance limitation associated with the usage of search filters in SuiteScript.
Source: Parameters 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 Searches

View all Searches articles →