Search.filterExpression

Note:

The content in this help topic pertains to SuiteScript 2.0.

Property Description

Use filter expressions as a shortcut to create filters (search.Filter).

A search filter expression is a JavaScript string array of zero or more elements. Each element is one of the following:

  • Operator – For a list of supported operators, see search.Operator.

  • Filter term

  • Two or more filter expressions combined logically with ‘and’, ‘or’, or ‘not. Logical operators are evaluated according to JavaScript operator precedence. For more information, see Operator precedence.

This property accepts nested arrays in which any element of the nested array can be an Object, a string, a number, or a boolean. Use null to set an empty array and remove any existing filter expressions on this search.

Note:

If you want to get or set search filters, use the Search.filters property.

Type

Array[]

Supported Script Types

Client and server scripts

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

Module

N/search Module

Since

2015.2

Note:

A filter expression is an array of filter elements defined with the options.filters parameter when creating a search using the search.create(options) method. This property is considered a shorthand way of defining filters, instead of using the search.createFilter(options) method.

Errors

Error Code

Message

Thrown If

SSS_INVALID_SRCH_FILTER_EXPR

Malformed search filter expression.

This is a general error raised when a filter expression cannot be parsed. For example:

[ f1, 'and', 'and', f2 ]

The options.filters parameter is not a valid search filter, filter array, or filter expression.

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 script sample below, each array of objects is considered to be a search filter expression. Filter expressions are automatically recognized and defined with the options.filters parameter.

          //Add additional code 
...
search.create({
    type: search.Type.CUSTOMER,
    filters: [
        ['email', search.Operator.STARTSWITH, 'kwolff'],
        'and',
        [
            ['id', search.Operator.EQUALTO, 107], 'or', 
            ['id',  search.Operator.EQUALTO, 2508]
        ]
    ]
});
...
//Add additional code 

        

Related Topics

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

General Notices