Creating Searches with SuiteScript in NetSuite

Create and manage searches in NetSuite with SuiteScript, utilizing filters, columns, and settings effectively.

·3 min read·View Oracle Docs

Starting with the SuiteScript API, you can create new searches that return a search.Search object. This enables you to modify, run, or save the search as per your requirements.

What is the Search Creation Method?

The search.create(options) method initializes a new search based on specified options. It is versatile, allowing for on-demand searches without saving. However, if you want to save your search for future use, simply call search.save(). The flexibility of this method allows you to utilize a variety of input formats for the options.filters argument, including a single search.Filter object or an array thereof.

Important Considerations for Search Creation

  • Ensure to sort the result using fields with unique values to maintain a consistent order of results.
  • Always use the internal ID of a field when creating filters or columns in SuiteScript; using text values will not work unless you use a formula.

Return Value

The method returns a search.Search object, which encapsulates the created search and its related functionality.

Supported Script Types

This method is usable in both client and server scripts.

Parameters

The options parameter is a JavaScript object with the following structure:

ParameterTypeRequired / OptionalDescription
options.typesearch.TypeRequiredThe type of search.
options.filtersVarious types including [search.Filter], array of filters, or stringsOptionalFilters for the search.
options.columnsVarious types including search.Column or array of columnsOptionalColumns to display in results.
options.titlestringOptionalTitle of the saved search.
options.idstringOptionalScript ID for the saved search.
options.isPublicbooleanOptionalIndicates if the search is public.

Error Codes

When working with the search.create method, you may encounter the following error codes:

  • SSS_INVALID_SRCH_COL — Invalid column specified.
  • SSS_INVALID_SRCH_FILTER_EXPR — Invalid filter expression provided.
  • SSS_MISSING_REQD_ARGUMENT — A required argument is missing.

Example Usage

The following code illustrates how to create a sales order search:

suitescript
1var mySalesOrderSearch = search.create({
2 type: search.Type.SALES_ORDER,
3 title: 'My Second SalesOrder Search',
4 id: 'customsearch_my_second_so_search',
5 columns: [{
6 name: 'entity'
7 }, {
8 name: 'subsidiary'
9 }, {
10 name: 'name'
11 }, {
12 name: 'currency'
13 }],
14 filters: [{
15 name: 'mainline',
16 operator: 'is',
17 values: ['T']
18 }],
19 settings: [{
20 name: 'consolidationtype',
21 value: 'AVERAGE'
22 }]
23});

This snippet provides a skeletal structure for implementing the search creation process, while reminding you of the flexibility it offers.

Key Takeaways

  • Use the search.create method to initiate searches efficiently.
  • Always sort searches by unique field values for consistent results.
  • Utilize internal field IDs when defining filters.

Source: This article is based on Oracle's official NetSuite documentation.

Frequently Asked Questions (4)

Do I need to use a unique field when sorting search results in SuiteScript?
Yes, it is important to sort the result using fields with unique values to maintain a consistent order of results.
Can I create a saved search using SuiteScript without immediately saving it?
Yes, the `search.create(options)` method allows for on-demand searches that do not need to be saved immediately unless you choose to do so using `search.save()`.
Are there specific field identifiers that must be used when creating filters and columns in SuiteScript?
Yes, you must use the internal ID of a field when creating filters or columns in SuiteScript, as text values will not work unless used within a formula.
What types of scripts can use the `search.create` method in SuiteScript?
The `search.create` method can be used in both client and server scripts in SuiteScript.
Source: Syntax Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Searches

View all Searches articles →