In SuiteScript, the search.lookupFields method is a powerful tool for retrieving specific field values from a record without performing a full search. This method is particularly useful for quickly accessing data with minimal overhead. However, it’s important to understand its capabilities and limitations. This article explores what data you can fetch using search.lookupFields and what you cannot. search.lookupFields is a method in SuiteScript that allows you to retrieve the values of specific fields from a record. It is designed to be efficient and straightforward, providing a way to access data without the need for a full search or loading the entire record.
What Data Can You Fetch?
Using search.lookupFields, you can fetch the following types of data:
- Standard Fields: You can retrieve values from standard fields on a record, such as
entityid,email,status,createddate, and more. These fields are commonly used and provide essential information about the record. - Custom Fields: You can also fetch values from custom fields that have been added to the record. This includes custom text fields, date fields, select fields, and more. Custom fields are identified by their internal IDs.
- Sublist Fields: While
lookupFieldsprimarily retrieves main record fields, it can also access certain sublist fields if they are specified correctly. However, this is limited and not as comprehensive as performing a full search on sublist data. - Related Fields: You can fetch values from related fields, such as fields on a parent or child record. For example, you can retrieve the name of a customer associated with a sales order.
Example Usage
Here’s an example of how to use search.lookupFields to fetch data from a record:
const search = require('N/search');
let customerData = search.lookupFields({
type: search.Type.CUSTOMER,
id: 12345,
columns: ['entityid', 'email', 'status']
});
console.log(customerData);
In this example, lookupFields retrieves the entityid, email, and status fields from a customer record with the ID 12345.
What Data You Cannot Fetch
While search.lookupFields is versatile, there are certain limitations:
- Complex Sublist Data:
lookupFieldsis not designed to retrieve complex sublist data, such as all line items on a transaction record. For detailed sublist data, you need to perform a full search or load the record and iterate through the sublist. - Aggregated Data: You cannot use
lookupFieldsto fetch aggregated data, such as sums, averages, or counts. For such data, you need to perform a saved search with appropriate summary criteria. - Multiple Records:
lookupFieldsretrieves data for a single record at a time. If you need to fetch data for multiple records, you should use a saved search. - Scripted Fields: Fields that are calculated or populated by scripts (e.g., formula fields) may not be reliably fetched using
lookupFields.
search.lookupFields is a valuable method in SuiteScript for quickly retrieving specific field values from a record. It is efficient and easy to use, making it ideal for accessing standard fields, custom fields, and related fields. However, it has limitations when it comes to complex sublist data, aggregated data, and multiple records. Understanding these capabilities and limitations will help you effectively utilize lookupFields in your SuiteScript development.