Search.run()

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Runs an on-demand search created with search.create(options) or a search loaded with search.load(options), returning the results as a search.ResultSet. Calling this method does not save the search.

Use this method with search.create(options) to create and run on-demand searches that are never saved to the database.

After you run a search, you can use ResultSet.each(callback) to iterate through the result set and process each result.

Important:

When you call this method, consider the following:

  • Search result sets are not cached. If records applicable to your search are created, modified, or deleted at the same time you are traversing your result set, your result set may change.

  • For better performance, consider creating a saved search in the UI and loading it in your script using search.load(options) instead of creating the search directly in your script using search.create(options).

Returns

search.ResultSet

Governance

None

Module

N/search Module

Since

2015.2

Errors

Error Code

Thrown If

SSS_INVALID_SRCH_SETTING

An unknown search parameter name is provided.

SSS_INVALID_SRCH_SETTING_VALUE

An unsupported value is set for the provided search parameter name.

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 
...
function loadAndRunSearch() {
    var mySearch = search.load({
        id: 'customsearch_my_so_search'
    });
    mySearch.run().each(function(result) {
        var entity = result.getValue({
            name: 'entity'
        });
        var subsidiary = result.getValue({
            name: 'subsidiary'
        });
        return true;
    });
} 

        

Related Topics

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

General Notices