search.createFilter(options)
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 |
Returns |
|
Supported Script Types |
Client and server scripts For more information, see SuiteScript 2.x Script Types. |
Governance |
None |
Module |
|
Since |
2015.2 |
Parameters
The options parameter is a JavaScript object.
Parameter |
Type |
Required / Optional |
Description |
Since |
---|---|---|---|---|
|
string |
required |
Name or internal ID of the search field. |
2015.2 |
|
string |
optional |
Join ID for the search filter. |
2015.2 |
|
string |
required |
Operator used for the search filter. Use the search.Operator enum. |
2015.2 |
|
string | Date | number | boolean | string[] | Date[] | number[] |
optional |
Values to be used as filter parameters. |
2015.2 |
|
string |
optional |
Formula used by the search filter. |
2015.2 |
|
string |
optional |
Summary type for the search filter. See search.Summary. |
2015.2 |
Errors
Error Code |
Message |
Thrown If |
---|---|---|
|
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. |
|
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. |
|
{1}: Missing a required argument: {2} |
Required parameter is missing. |
Syntax
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
If you set contains search filters for fields with Long Text and Rich Text text types, the matching string length has a limit of approximately 500 characters. This limit may vary depending on the character encoding you use.