Speeding Up a Saved Search in NetSuite by Splitting It

in , March 15th, 2024

While working with NetSuite Saved Searches, we have found that in certain cases, it is possible to reduce the time it takes to complete a search query by up to 10x by splitting the search into two or more separate searches. This is especially the case if you are using “OR” conditionals in your search and/or if your search is returning thousands of results.

Need to be able to get around NetSuite's 4000 line saved search result limit? Check out our article on Returning Unlimited Saved Search Results in NetSuite!

Example Saved Search and Speed Impact

A concrete example is as follows:

var newSearch = search.create({
        type: "transaction",
        filters: [
            ["mainline", "is", "T"],
            "AND",
            ["type", "anyof", ["CustInvc", "SalesOrd", "CustCred"]],
            "AND",
            [["entity", "is", userId], "OR", ["custbody_ship_to_customer", "is", userId]],
        ],
        columns: [
            search.createColumn({
                name: "tranid",
                sort: search.Sort.ASC,
            }),
            search.createColumn({
                name: "custbody_nsps_vin_number",
                sort: search.Sort.ASC,
            }),
            search.createColumn({
                name: "custbody_nsps_web_ponum",
                sort: search.Sort.ASC,
            }),
            search.createColumn({
                name: "custbody_nsps_web_part_num",
                sort: search.Sort.ASC,
            }),
            "entity",
            "type",
        ],
    });

The above search grabs Sales Orders, Invoices, and Credits for the logged-in user as well as any of those transactions that have the logged-in user set in a custom field (“custbody_ship_to_customer").

This search was taking over 35 seconds to execute for some users. (Which is extremely slow!)

So, how could we split up this example search to try to speed up the time to execute? In this case, we can split the saved search into two searches since there are two filters.

For other saved searches with a larger number of filters, you may find that you need to split your saved search into more than two searches. However, it may not be necessary to always split every filter out into its own search.

Continuing with our example, after we split it out into two searches the first search included just the “["entity", "is", userId]" filter while the second included just the “["custbody_ship_to_customer", "is", userId]"filter.

By splitting this particular search into two separate searches, one for each filter, the execution time was reduced from 35 seconds to less than 4 seconds!

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!

 
 

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