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.
Source: This article is based on Oracle's official NetSuite documentation.
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 Platform
- Style Object Members for Workbook API in NetSuite
The Style object provides customizable properties for workbook formatting in NetSuite, enhancing report and visualization functionality.
- Asynchronous HTTP Requests with SuiteScript Promises
Use SuiteScript to send asynchronous HTTP requests with promises for efficient error handling and response processing.
- Setting Sublist Field Values in SuiteScript
Set values for sublist fields in SuiteScript using the setSublistValue method. Understand required parameters and error handling.
- In This Help Topic
Explore N/log module guidelines, log levels, and script execution logs for efficient logging in SuiteScript.
Advertising
Reach Platform Professionals
Put your product in front of NetSuite experts who work with Platform every day.
Sponsor This Category