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
- Common SuiteScript Errors and Solutions for NetSuite
Common NetSuite script errors include INVALID_SCRIPT_DEPLOYMENT_ID and SSS_AUTHORIZATION_HEADER_NOT_ALLOWED. Learn effective solutions.
- Set Sublist Field Values in SuiteScript 2.x for Record Management
Set sublist field values in SuiteScript 2.x for effective record management using standard and dynamic modes.
- Setting Field Values in SuiteScript for Effective Record
Learn to set field values in SuiteScript effectively, troubleshooting common errors and understanding data types.
- SuiteScript 2.1 Enhancements and API Updates in NetSuite
SuiteScript 2.1 enables execution of 2.0 scripts and supports PATCH method for enhanced API capabilities.
Advertising
Reach SuiteScript Professionals
Put your product in front of NetSuite experts who work with SuiteScript every day.
Sponsor This Category