Creating Search Columns in SuiteScript for NetSuite
Creating search columns in SuiteScript allows precise retrieval of fields in search results, enhancing data analysis and reporting.
Creating search columns is fundamental in SuiteScript, allowing developers to fetch specific field values when executing searches against records. This article provides an overview of how to create search columns, discusses important considerations, returns data, and outlines potential errors you might encounter during the process.
What is a Search Column?
A search column in SuiteScript represents a field on a record. When you create a column for a specific field—for example, the Sales Rep field on a customer record—and include it in your search criteria, this field's value will appear in the search results subsequently.
Important Considerations
As you create search columns, there are some critical points to keep in mind:
- Internal IDs: When dealing with a list or record type field, use the field's internal ID instead of its text value. If you need to use the text value, create a filter or column that utilizes a formula via
name: 'formulatext'. - Sort Order: Once a column is created, its sort order cannot be changed on the fly. If used in multiple searches, the initial sort order specified via the
options.sortparameter remains fixed.
Method Syntax
To create a new search column, you'll use the search.createColumn(options) method. The following parameters can be included:
| Parameter | Type | Required/Optional | Description |
|---|---|---|---|
options.name | string | required | Name of the search column. |
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 the search column. |
options.function | string | optional | Special function for the search column. |
options.label | string | optional | Label for the search column. |
options.sort | string | optional | Sort order of the column. |
Example Code
Here’s a basic example of how to create a search column in SuiteScript:
var currencyColumn = search.createColumn({ name: 'currency', sort: search.Sort.ASC});This creates a column for the currency field and specifies that the results should be sorted in ascending order by this column.
Error Handling
When creating search columns, you may encounter the following errors:
| Error Code | Message | Thrown If |
|---|---|---|
SSS_INVALID_SRCH_COLUMN_SUM | Invalid summary type or incorrect syntax. | The options.summary is not valid. |
INVALID_SRCH_FUNCTN | An unknown function was provided. | The function does not match expected formats. |
SSS_MISSING_REQD_ARGUMENT | Missing required argument specified. | One or more required parameters are missing. |
Conclusion
Understanding how to create search columns effectively can greatly enhance data retrieval capabilities within SuiteScript. By carefully managing parameters and error handling, developers can ensure efficient and accurate queries in their NetSuite applications.
Key Takeaways
- Search columns represent fields on records for customized search results.
- Use internal IDs for list/record type fields when defining columns.
- Sort orders are fixed after column creation and cannot be overridden in subsequent searches.
- Familiarize yourself with common errors in creation to streamline debugging and development processes.
Frequently Asked Questions (4)
Do I need to use internal IDs for list or record type fields when creating search columns in SuiteScript?
Can I change the sort order of a search column after it is created in SuiteScript?
What are the required parameters for creating a search column using 'search.createColumn' in SuiteScript?
What error might occur if an invalid summary type is used when creating a search column?
Was this article helpful?
More in Searches
- Creating Searches with SuiteScript in NetSuite
Create and manage searches in NetSuite with SuiteScript, utilizing filters, columns, and settings effectively.
- Filter Object Members for N/Search Module in NetSuite
Filter Object Members enhance search capabilities in NetSuite SuiteScript. Learn to create and configure filters effectively.
- 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.
- Error Handling in Searches with SuiteScript 2.0 Features
Gain insights into error handling in SuiteScript searches, including codes and common issues that arise when loading saved searches.
Advertising
Reach Searches Professionals
Put your product in front of NetSuite experts who work with Searches every day.
Sponsor This Category