search.lookupFields(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Performs a search for one or more body fields on a record.

You can use joined-field lookups with this method, with the following syntax:

join_id.field_name

The search.lookupFields(options) method also includes a promise version, search.lookupFields.promise(options). For more information about promises, see Promise Object.

Note that the return contains either an object or a scalar value, depending on whether the looked-up field holds a single value, or a collection of values. Single select fields are returned as an object with value and text properties. Multi-select fields are returned as an object with value:text pairs.

In the following example, a select field like my_select would return an array of objects containing a value and text property. This select field contains multiple entries to select from, so each entry would have a numerical id (the value) and a text display (the text).

For "internalid" in this particular code sample, the sample returns 1234. The internal id of a record is a single value, so a scalar is returned.

                    {
    internalid: 1234,
    firstname: 'Joe',
    my_select: [{
        value: 1,
        text: 'US Sub'
    }],
    my_multiselect: [
        {
            value: 1,
            text: 'US Sub'
        },
        {
            value: 2,
            text: 'EU Sub'
        }
    ]
} 

                  

If you try to look up a field that does not exist on the specified record, an SSS_INVALID_SRCH_COL error is thrown.

Returns

Object | Object[]

  • Returns select fields as an object with value and text properties.

  • Returns multiselect fields as an array of object with value:text pairs.

Supported Script Types

Client and server scripts

For more information, see SuiteScript 2.x Script Types.

Governance

1 unit

Module

N/search Module

Since

2015.2

Important:

In search/lookup operations, custom multiselect fields of type "long text" are truncated at 4,000 characters. In accounts with multiple languages enabled, the returned value is truncated at 1,300 characters. In accounts that don’t use multiple languages, the field return truncates at 3,900 characters. You can use the record.load(options) method as an alternative for retrieving desired results.

Parameters
Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

Since

options.type

enum

Required

The search type for which you want to look up fields. Use the search.Type enum for this argument.

2015.2

options.id

string

Required

Internal ID for the record, for example 777 or 87.

2015.2

options.columns

string | string[]

Required

Array of column/field names to look up, or a single column/field name. The columns parameter can also be set to reference joined fields.

2015.2

Errors

Error Code

Message

Thrown If

SSS_INVALID_SRCH_COL

An nlobjSearchColumn contains an invalid column, or is not in proper syntax: {1}.

The options.columns parameter includes invalid columns for the specified record.

SSS_MISSING_REQD_ARGUMENT

{1}: Missing a required argument: {2}

Required parameter is missing.

Syntax
Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/search Module Script Samples.

          //Add additional code
...
var fieldLookUp = search.lookupFields({
    type: search.Type.SALES_ORDER,
    id: '87',
    columns: ['entity', 'subsidiary', 'name', 'currency']
});
...
//Add additional code 

        

Related Topics

N/search Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices