SuiteScript LookupFields Parameters and Syntax Reference
SuiteScript LookupFields method enables searching body fields with specific parameters and handling errors effectively.
The SuiteScript lookupFields method facilitates searching and retrieving one or more body fields on a record, returning structured results based on the specified parameters. This method allows developers to access record data efficiently, categorizing the returns depending on whether fields are single-value or multi-select.
How Does the LookupFields Method Work?
This method allows for joined-field lookups using the syntax join_id.field_name. The structure of returned values differs based on the type of field accessed:
- Single Select Fields: These return an object with
valueandtextproperties. - Multi-Select Fields: These return an array of objects with value:text pairs.
For example, a simple return for an internal ID might look like this:
1{2 internalid: 1234,3 firstname: 'Joe',4 my_select: [{5 value: 1,6 text: 'US Sub'7 }],8 my_multiselect: [9 {10 value: 1,11 text: 'US Sub'12 },13 {14 value: 2,15 text: 'EU Sub'16 }17 ]18}How to Define the Options Parameter
The options parameter is a JavaScript object that includes the following properties:
| Parameter | Type | Required / Optional | Description |
|---|---|---|---|
options.type | enum | required | The search type for the record. Use the search.Type enum. |
options.id | string | required | Internal ID for the record (e.g., 777 or 87). |
options.columns | `string | string[]` | required |
Error Handling in LookupFields
When operating with the lookupFields method, two primary errors can occur:
SSS_INVALID_SRCH_COL: Thrown when an invalid or incorrectly formatted column is referenced in theoptions.columnsparameter.SSS_MISSING_REQD_ARGUMENT: Indicates that a required argument is missing from the options.
Governance
For each execution, the method consumes 1 governance unit.
Example Syntax
Here’s a basic example to demonstrate how to use the lookupFields method:
var fieldLookUp = search.lookupFields({ type: search.Type.SALES_ORDER, id: '87', columns: ['entity', 'subsidiary', 'name', 'currency']});In this example, the method retrieves the specified fields from a sales order with ID 87.
Key Points to Remember
- The
lookupFieldsmethod is synchronous; consider using its promise-based alternative for non-blocking calls. - Always validate the
optionsparameters to avoid errors and ensure efficient searches.
Key Takeaways
- The
lookupFieldsmethod efficiently retrieves field data with defined parameters. - Supports both single select and multi-select field formats.
- Error handling is crucial for maintaining smooth executions.
- Governance limits may affect script performance, ensuring efficient use is essential.
Frequently Asked Questions (4)
What parameters are required when using the lookupFields method in SuiteScript?
How does the lookupFields method handle multi-select fields?
What are common errors encountered with SuiteScript's lookupFields method?
Does the lookupFields method in SuiteScript support asynchronous operations?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
