search.create(options)

Method Description

Creates a new search and returns it as a search.Search object.

The search can be modified and run as an on demand search with Search.run(), without saving it. Alternatively, calling Search.save() will save the search to the database, so it can be reused later in the UI or loaded with search.load(options).

Note:

This method is agnostic in terms of its options.filters argument. It can accept input of a single search.Filter object, an array of search.Filter objects, or a search filter expression.

The search.create(options) method also includes a promise version, search.create.promise(options). For more information about promises, see Promise Object.

Important:

When you use this method to create a search, consider the following:

  • When you define the search, make sure you sort using the field with the most unique values, or sort using multiple fields. Sorting with a single field that has multiple identical values can cause the result rows to be in a different order each time the search is run.

  • 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.Search

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.type

string

required

The search type that you want to base the search on. Use the search.Type enum for this argument.

2015.2

options.filters

search.Filter | search.Filter[] | Object | Object[] | string | string[]

optional

A single search.Filter object, an array of search.Filter objects, a search filter expression, or an array of search filter expressions.

A search filter expression can be passed in as an Object with the following properties:

  • name (required)

  • join

  • operator (required)

  • summary

  • formula

  • values

For more information about these properties, see Filter Object Members.

If a provided filter value has an incorrect type (for example, a string instead of a number), the filter value is ignored. For server scripts, a log entry is created when an incorrect type is provided.

Note:

You can further filter the returned search.Search object by adding additional filters with Search.filters or Search.filterExpression.

2015.2

options.filterExpression

Object[]

optional

Search filter expression for the search as an array of expression objects.

A search filter expression is created when an array of JavaScript objects are passed through the options.filters parameter. This value is set with an array of expression objects or single filter expression objects to overwrite any prior filter expressions.

Note:

A filter expression is automatically recognized by NetSuite. Filter expressions should not be explicitly denoted when scripting. A filter expression should be used with the options.filters parameter. For more information about how to set the values of this parameter, see Search.filterExpression.

2016.2

options.columns

search.Column | search.Column[] | Object | Object[] | string | string[]

optional

A single search.Column object or array of search.Column objects.

You can optionally pass in an Object or array of Objects with the following properties to represent a Column:

  • name (required)

  • formula

  • function

  • join

  • label

  • sort

  • summary

For more information about these properties, see Column Object Members.

2015.2

options.packageId

string

optional

The application ID for this search.

2019.2

options.settings

search.Setting | search.Setting[] | Object | Object[] | string | string[]

optional

Search settings for this search as a single search.Setting object or an array of search.Setting objects. Search settings let you specify search parameters that are typically available only in the UI. See Search.settings.

You can optionally pass in an Object or array of Objects with the following properties to represent a setting:

  • name

  • value

For more information about these properties, see Setting Object Members.

2018.2

options.title

string

optional

The name for a saved search. The title property is required to save a search with Search.save().

2015.2

options.id

string

optional

Script ID for a saved search. If you do not set the saved search ID, NetSuite generates one for you. See Search.id.

2015.2

options.isPublic

boolean

optional

Set to true to make the search public. Otherwise, set to false. If you do not set this parameter, it defaults to false.

This parameter sets the value for the Search.isPublic property.

2016.2

Errors

Error Code

Thrown If

SSS_INVALID_SRCH_COL

The options.columns parameter is not a valid column, string, or column or string array.

SSS_INVALID_SRCH_FILTER_EXPR

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

SSS_MISSING_REQD_ARGUMENT

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.

          //Add additional code 
...
var mySalesOrderSearch = search.create({
    type: search.Type.SALES_ORDER,
    title: 'My Second SalesOrder Search',
    id: 'customsearch_my_second_so_search',
    columns: [{
        name: 'entity'
    }, {
        name: 'subsidiary'
    }, {
        name: 'name'
    }, {
        name: 'currency'
    }],
    filters: [{
        name: 'mainline',
        operator: 'is',
        values: ['T']
    }],
    settings: [{
        name: 'consolidationtype',
        value: 'AVERAGE'
    }]
});
...
//Add additional code 

        

Related Topics

General Notices