SuiteScript LookupFields Parameters and Syntax Reference

SuiteScript LookupFields method enables searching body fields with specific parameters and handling errors effectively.

·2 min read·View Oracle Docs

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 value and text properties.
  • 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:

suitescript
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:

ParameterTypeRequired / OptionalDescription
options.typeenumrequiredThe search type for the record. Use the search.Type enum.
options.idstringrequiredInternal ID for the record (e.g., 777 or 87).
options.columns`stringstring[]`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 the options.columns parameter.
  • 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:

suitescript
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 lookupFields method is synchronous; consider using its promise-based alternative for non-blocking calls.
  • Always validate the options parameters to avoid errors and ensure efficient searches.

Source: This article is based on Oracle's official NetSuite documentation.

Key Takeaways

  • The lookupFields method 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?
The lookupFields method requires the following parameters: 'type', 'id', and 'columns'. 'type' should be an enumerated value from search.Type. 'id' is the internal ID of the record you wish to access, and 'columns' is a string or an array of strings indicating the fields to look up.
How does the lookupFields method handle multi-select fields?
For multi-select fields, the lookupFields method returns an array of objects, each containing a 'value' and 'text' representing the select options available for that field.
What are common errors encountered with SuiteScript's lookupFields method?
Two common errors include 'SSS_INVALID_SRCH_COL', which occurs when an invalid column is specified, and 'SSS_MISSING_REQD_ARGUMENT', indicating a missing required parameter in the options.
Does the lookupFields method in SuiteScript support asynchronous operations?
No, the lookupFields method is synchronous. For non-blocking calls, you should consider using its promise-based alternative.
Source: Parameters Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Platform

View all Platform articles →