netsuiteLookup Data from Related Records


Introduction

When processing a given record, you will oft need to retrieve data from one of its related records. For example, when working with a given Sales Order, you may need to retrieve data from the related Sales Rep. In SuiteScript terminology, this is called a lookup.

Lookup functionality is provided by the nlapiLookupField global function in SuiteScript 1.0 and the N/search module's lookupFields method in SuiteScript 2.0

Syntax

  • nlapiLookupField(recordType, recordId, columns);

Parameters

ParameterDetails
recordTypeString - The internal ID of the type of record being looked up (e.g. salesorder, employee)
recordIdString or Number - The internal ID of the record being looked up
columnsString or String[] - The list of fields to retrieve from the record. Field IDs can be referenced from the "Search Columns" section of the Records Browser. Joined fields can be retrieved using dot syntax (e.g. salesrep.email)

Remarks

Performance

A Lookup is just shorthand for performing a search that filters on the internal ID of a single record for the result. Under the hood, lookups are actually performing a search, so the performance will be similar to that of a search that returns a single record.

This also means that a lookup will perform faster than loading the record to retrieve the same information.

Limitations

Lookups can only be used to retrieve body field data. You cannot retrieve data from the sublists of a related record using a lookup. If you need sublist data, you will either need to perform a search or load the related record.