search.createFilter(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Creates a new search filter as a search.Filter object.

Important:

You cannot directly create a filter or column for a list/record type field in SuiteScript by passing in its text value. You must use the field’s internal ID. If you must use the field’s text value, you can create a filter or column with a formula using name: 'formulatext'.

Returns

search.Filter

Supported Script Types

Client and server scripts

For more information, see SuiteScript 2.x Script Types.

Governance

None

Module

N/search Module

Since

2015.2

Parameters
Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

Since

options.name

string

Required

Name or internal ID of the search field.

2015.2

options.join

string

Optional

Join ID for the search filter.

2015.2

options.operator

string

Required

Operator used for the search filter. Use the search.Operator enum.

2015.2

options.values

string | Date | number | boolean | string[] | Date[] | number[]

Optional

Values to be used as filter parameters.

2015.2

options.formula

string

Optional

Formula used by the search filter.

2015.2

options.summary

string

Optional

Summary type for the search filter. See search.Summary.

2015.2

Errors

Error Code

Message

Thrown If

SSS_INVALID_SRCH_OPERATOR

An search.Filter object contains an invalid operator, or is not in proper syntax: {1}.

options.operator parameter is not a valid operator type. See search.Operator.

SSS_INVALID_SRCH_SUMMARY_TYP

A search.Column object contains an invalid column summary type, or is not in proper syntax: {1}.

options.summary parameter is not a valid search summary type. See search.Summary.

SSS_MISSING_REQD_ARGUMENT

{1}: Missing a required argument: {2}

Required parameter is missing.

Syntax
Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/search Module Script Samples.

In the code sample below, the options.filters parameter creates search.createFilter(options) objects. For an example of filter expressions created using the options.filters parameter, see Search.filterExpression.

          // Add additional code 
...
// Create a filter joined to another record type. When you create a joined filter:
// - The name property is the field ID of the field in the joined record that you are filtering on
// - The join property is the field ID of the field in the current record that contains the record
//   type you want to join to
// - The operator property is the operator to use to filter the results
// - The values property contains the values to use to filter the results
//
// For example, the following search definition lists the first 100 employees found
// who have a custom role. The search definition specifies that the search applies to
// Employee records. The filter definition joins the Role record type to the search
// and returns results where the iscustom field (a field on the Role record) is true.
var result = search.create({
    type: 'employee',
    columns: ['firstname', 'lastname', 'role'],
    filters: [
        search.createFilter({
            name: 'iscustom',
            join: 'role',
            operator: search.Operator.IS,
            values: true
        })
    ]
}).run().getRange({
    start: 0,
    end: 100
});
log.debug({
    title: 'Result',
    details: result
});
...
// Add additional code 

        

Related Topics

N/search Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices