Creating Search Columns in SuiteScript for NetSuite
Master search column creation in SuiteScript to enhance search results with specific fields and their properties.
Creating new search columns in SuiteScript allows developers to specify fields that should be represented in the search results. A search column is an object that corresponds to a specific field in a record and is instrumental in customizing search output to business needs.
What is a Search Column?
A search column represents a specific field on a record that you want to include in the returned search results. For instance, if you want to display the Sales Rep field from a customer record in your search results, you would create a column for that field when defining your search criteria.
Important Considerations
When creating search columns, you should be aware of the following:
- Field Internal IDs: Directly referencing the text value of a list/record type field is prohibited. Instead, use the internal ID of the field. If you need to use the text value, you can implement a formula with
name: 'formulatext'. - Sorting Limitations: After a search column has been created, its sort order cannot be changed. If you use the same column in multiple searches, the original sort order specified with
options.sortwill be retained.
How to Create a Search Column
To create a search column in SuiteScript, you'll use the search.createColumn(options) method. The options object allows you to define various parameters for your search column.
Parameters
| Parameter | Type | Required / Optional | Description |
|---|---|---|---|
options.name | string | required | Name of the search column, linked to the field. |
options.join | string | optional | Join ID for the search column. |
options.summary | string | optional | Summary type for the column. |
options.formula | string | optional | Formula for derived column values. |
options.function | string | optional | Special function applied to the column. |
options.label | string | optional | Label for the search column. |
options.sort | string | optional | Specifies the sorting order of the column. |
Example Code
Here’s a basic example of creating a search column using SuiteScript:
var currencyColumn = search.createColumn({ name: 'currency', sort: search.Sort.ASC});This snippet creates a column for the currency field and sets it to sort in ascending order.
Error Handling
While crafting your search column, you might encounter several errors:
- SSS_INVALID_SRCH_COLUMN_SUM: Thrown when an invalid column summary type is used in the
options.summaryparameter. - INVALID_SRCH_FUNCTN: Returned if an unrecognized function is provided for the search column.
- SSS_MISSING_REQD_ARGUMENT: Occurs when a required parameter is missing during column creation.
Conclusion
By effectively utilizing the search.createColumn method, developers can tailor their SuiteScript searches to meet specific business requirements, improving the clarity and relevance of search outputs.
Source: This article is based on Oracle's official NetSuite documentation.
Frequently Asked Questions (4)
Do search columns in SuiteScript retain their sort order if used in multiple searches?
What error might occur if I use an invalid summary type for a search column?
Can I use the text value of a list/record type field directly when creating a search column?
What happens if a required parameter is missing when creating a search column in SuiteScript?
Was this article helpful?
More in Searches
- Search for Sublist Line Fields With Dynamic Tables in NetSuite
Learn how to optimize search queries for sublist line fields in NetSuite using dynamic tables and SuiteQL.
- Filter Object Members in NetSuite SuiteScript
Gain insights into the Filter Object Members of the N/search module in NetSuite SuiteScript. Learn how to create and configure filters effectively.
- Search Column Syntax for SuiteScript 2.x in NetSuite
Search column syntax in SuiteScript 2.x allows encapsulation of fields in NetSuite searches, enhancing data retrieval capabilities.
- PagedData Object Members in NetSuite SuiteScript 2.0
PagedData provides efficient pagination for search results in SuiteScript, enabling effective handling of large data sets.
Advertising
Reach Searches Professionals
Put your product in front of NetSuite experts who work with Searches every day.
Sponsor This Category