The Speed of Searching for Record Data vs. Loading the Record in SuiteScripts

in , October 14th, 2024
time lapse photography of tunnel

Speed is an important feature in any scripting exercise. Optimizing scripts for speed should be a top priority when writing SuiteScripts. When deciding how to lookup data in a SuiteScript two options are used most frequently, “searching” with the “search” module and loading a record with the “record” module.

Testing Script Speed: Code Example

We have found when testing script speeds that searching is usually an order of magnitude faster than loading a record and looking up the value. See code examples here:

//N_search refers to the "search" module
var field = N_search.lookupFields({
    type: "item",
    id: context.newRecord.id,
    columns: [
        "itemid",
    ],
});
//the process above will be much faster than the process below 
//N_record refers to the "record" module
let itemRecord = N_record.load({
    type: context.newRecord.type,
    id: context.newRecord.id,
});
itemRecord.getValue("itemid");

Using “search.lookupFields” will get the record data 5-10 times faster than loading the record, even when searching for many (10+) fields.

When using search is NOT fastest...

There is an instance, though, where using a search is not fastest. If the record object has already been loading for whatever reason (perhaps loading is required for some other logic in the code) a search will then be slower than simply using the “getValue” API.

Author: Sam Gagliardi


Got stuck on a step in this article?

We like to update our blogs and articles to make sure they help resolve any troubleshooting difficulties you are having. Sometimes, there is a related feature to enable or a field to fill out that we miss during the instructions. If this article didn't resolve the issue, please use the chat and let us know so that we can update this article!


Oracle NetSuite Alliance Partner & Commerce Partner

If you have general questions about SuiteCommerce or more specific questions about how our team can support your business as you implement NetSuite or SuiteCommerce, feel free to contact us anytime. Anchor Group is a certified Oracle NetSuite Alliance Partner and Commerce Partner equipped to handle all kinds of NetSuite and SuiteCommerce projects, large or small!

 
 

Want to keep learning?

Our team of NetSuite professionals has written articles on a wide variety of NetSuite topics, from SuiteCommerce tips, to recommended NetSuite solutions, to available support services, and more! 

Your cart