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
- 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.
- PagedData Object Members in NetSuite SuiteScript 2.0
PagedData provides efficient pagination for search results in SuiteScript, enabling effective handling of large data sets.
- Search Object Errors in SuiteScript for NetSuite
Understand common search object errors in SuiteScript for NetSuite and how to resolve them effectively.
- Search Filter Object Usage in SuiteScript
The Search Filter object enables refined query capabilities in SuiteScript, encapsulating search criteria.
Advertising
Reach Searches Professionals
Put your product in front of NetSuite experts who work with Searches every day.
Sponsor This Category