Creating and Managing Searches with SuiteScript 2.1

The search.create() method in SuiteScript enables developers to create and run searches efficiently, enhancing data retrieval processes in NetSuite.

·3 min read·View Oracle Docs

TL;DR

The search.create(options) method in SuiteScript allows you to create new searches within the NetSuite platform, returning them as search.Search objects. This method supports various input types and allows for extensive data filtration and customization.

What is search.create(options)?

The search.create(options) method is a powerful functionality in SuiteScript that enables developers to create searches dynamically. This method can directly run searches without saving them or can save them for future use.

How Does It Work?

When implementing the search.create() method, you need to provide an options parameter, which is a JavaScript object that specifies how the search should be constructed. This method can be used as follows:

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: [{ name: 'entity' }, { name: 'subsidiary' }, { name: 'name' }, { name: 'currency' }],
6 filters: [{ name: 'mainline', operator: 'is', values: ['T'] }],
7 settings: [{ name: 'consolidationtype', value: 'AVERAGE' }]
8});

Parameters

The options object can include the following parameters:

ParameterTypeRequired / OptionalDescription
options.typesearch.TyperequiredThe search type, which specifies the context for the search.
options.filterssearch.Filter, Object, or stringoptionalAccepts a single or an array of search filter objects. Supports filter expressions.
options.filterExpressionObject[]optionalDefines a search filter expression as an array of objects.
options.columnssearch.Column, ObjectoptionalIncludes search column configurations.
options.packageIdstringoptionalApplication ID for the search.
options.titlestringoptionalRequired when saving a search for identification.
options.idstringoptionalAutomatically generated unless specified; denotes the script ID.
options.isPublicbooleanoptionalDetermines if the search is publicly accessible (default is false).

Important Considerations

  • Sorting: When defining a search, consider sorting with fields that have unique values to minimize inconsistency in search results.
  • Filters: Filters for record types must use internal IDs rather than text values. However, you can utilize formulas for complex queries.

Errors

Common error codes associated with the search.create() method include:

  • SSS_INVALID_SRCH_COL: Invalid column type in the options.columns parameter.
  • SSS_INVALID_SRCH_FILTER_EXPR: Invalid filter expression in the options.filters parameter.
  • SSS_MISSING_REQD_ARGUMENT: Required parameters not provided.

Who This Affects

This functionality is particularly relevant for:

  • Developers: Implementing custom searches and reports in SuiteScript.
  • Administrators: Overseeing and managing saved searches and custom scripts in the NetSuite environment.

Key Takeaways

  • The search.create() method facilitates dynamic, on-demand search creation in SuiteScript.
  • Utilize unique sorting fields to ensure consistent search results.
  • Be cautious with filter parameters, ensuring correct data types are provided.

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

Frequently Asked Questions (4)

How can I specify which records to include in a SuiteScript search?
You can specify which records to include using the 'filters' parameter or the 'filterExpression' in the 'options' object when creating a search. Filters should use internal IDs, and you can utilize formulas for more complex queries.
Do I need to provide a unique 'id' when creating a search with search.create()?
You don't need to provide a unique 'id', as it is automatically generated unless specified. However, if you want to identify the search script specifically, you can provide an 'id'.
Can I make a search publicly accessible when using search.create()?
Yes, you can make a search publicly accessible by setting the 'isPublic' parameter to true in the 'options' object. By default, 'isPublic' is set to false.
What error should I be mindful of when adding columns to my SuiteScript search?
When adding columns, be aware of the 'SSS_INVALID_SRCH_COL' error, which occurs if an invalid column type is provided in the 'options.columns' parameter.
Source: Parameters 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 →