ANS-0653 · SUITESCRIPT DEVELOPMENT

NetSuite Scripting: Which is Faster, nlapiLookupField or nlapiLoadRecord?

A performance test reveals significant execution time differences between retrieving specific field values using direct lookup versus loading an entire record.

Short answer

For retrieving a limited number of field values in NetSuite SuiteScript, direct lookup functions are significantly more efficient than loading the entire record. Performance tests indicate that nlapiLookupField (or N/search.lookupFields in SuiteScript 2.x) is approximately 50 times faster than nlapiLoadRecord (or N/record.load) followed by field retrieval. This optimization is crucial for script performance.

Scenario

Developers often need to retrieve specific field values from NetSuite records within SuiteScript. A common question arises regarding the most efficient method for this task: directly looking up the field value or loading the entire record and then extracting the field. Understanding the performance implications of these two approaches is vital for optimizing script execution time.

Solution

Performance tests conducted on NetSuite records demonstrate that retrieving a single or a few field values using a direct lookup function is significantly faster than loading the entire record and then accessing the desired field. Specifically, nlapiLookupField was found to be approximately 50 times faster than the combination of nlapiLoadRecord() and getFieldValue(). While the test was performed using SuiteScript 1.0 functions, the underlying performance principle remains valid for their SuiteScript 2.x counterparts, N/search.lookupFields and N/record.load respectively. NetSuite strongly recommends using SuiteScript 2.x for all new or substantially revised scripts. The test involved extracting 100 customer and sales order records using a saved search within a scheduled script. For each record, the execution time for nlapiLookupField() was measured in a loop, and then compared against the execution time for nlapiLoadRecord() followed by getFieldValue(). The following SuiteScript 1.0 code was used to perform this performance comparison:

javascriptfunction testForGoodman() {var filters  [];var columns  [];//Built filters for the searchfilters.push(new nlobjSearchFilter('isinactive', null, 'is', 'F'));//Built columns for the searchcolumns.push(new nlobjSearchColumn('entityid'));//Run the searchvar recordSearchCustomer  nlapiSearchRecord('customer', null, filters, columns);var filters  [];var columns  [];//Built filters for the searchfilters.push(new nlobjSearchFilter('entity', null, 'noneof', 'q'));//Built columns for the searchcolumns.push(new nlobjSearchColumn('entity'));//Run the searchvar recordSearchSales  nlapiSearchRecord('salesorder', null, filters, columns);//******************Customer****************var dateCustomerBefore  new Date();var timeBeforeCust  dateCustomerBefore.getTime();var customerDivider  100;for (var i  0; i < customerDivider; i++) {    nlapiLookupField('customer', recordSearchCustomer[i].getId(), 'entityid');}var dateCustomerAfter  new Date();var timeAfterCust  dateCustomerAfter.getTime();nlapiLogExecution('debug', 'Customer Time For nlapiLookupField',(timeAfterCust - timeBeforeCust));var dateCustomerBefore  new Date();var timeBeforeCust  dateCustomerBefore.getTime();for (var i  0; i < customerDivider; i++) {    var rec  nlapiLoadRecord('customer', recordSearchCustomer[i].getId());    rec.getFieldValue('entityid');}var dateCustomerAfter  new Date();var timeAfterCust  dateCustomerAfter.getTime();nlapiLogExecution('debug', 'Customer Time FornlapiLoadRecord+getField', (timeAfterCust - timeBeforeCust));//*******************sales***********var dateSalesBefore  new Date();var timeBeforeSales  dateSalesBefore.getTime();var salesDivider  100;for (var i  0;  i < salesDivider; i++) {    nlapiLookupField('salesorder', recordSearchSales[i].getId(), 'entity');}var dateSalesAfter  new Date();var timeAfterSales  dateSalesAfter.getTime();nlapiLogExecution('debug', 'Sales Time For nlapiLookupField',(timeAfterSales - timeBeforeSales));var dateSalesBefore  new Date();var timeBeforeSales  dateSalesBefore.getTime();for (var i  0;  i < salesDivider; i++) {    var rec  nlapiLoadRecord('salesorder', recordSearchSales[i].getId());    rec.getFieldValue('entity');}var dateSalesAfter  new Date();var timeAfterSales  dateSalesAfter.getTime();nlapiLogExecution('debug', 'Sales Time For nlapiLoadrecord+getField',(timeAfterSales - timeBeforeSales));}

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant