Dynamic Saved Searches in NetSuite: No Suitelets or Multiple Searches Needed

By Bobby Stevens

The Problem

Sometimes we want to create links to NetSuite saved searches that automatically adapt their results based on specific information. For instance, you might want a link on a customer record that displays only that customer’s relevant data. The traditional approaches might involve multiple saved searches or custom Suitelets. But there’s a simpler way!

The Solution: Dynamic Filters

Here’s the basic outline of how to achieve this:

  1. Create Your Saved Search: Build a saved search on the desired record type (e.g., customers). Initially, you don’t need any filters.
  2. Write a Simple Suitelet: This Suitelet does the following:
    • Takes an internal ID parameter from the URL (intId).
    • Loads your saved search.
    • Adds a filter to that search, narrowing the results using the provided intId.
    • Redirects the user to the filtered search results page.
  3. Client-Script Magic: A client-script on the relevant record type (e.g., customer) constructs the Suitelet’s URL, attaches the record’s internal ID as a parameter, and opens the link in a new window.

Example Code

Here’s a simplified illustration (replace placeholders like ‘custom_script’ with your actual IDs):

Suitelet

/**
 * @NApiVersion 2.1
 * @NScriptType Suitelet
 */
define(['N/search'], function (search) {
    function onRequest(context) {
        const customerId = context.request.parameters.intId; 

        var mySearch = search.load({ id: 'customsearch_my_so_search' }); // Your saved search 
        mySearch.filters.push(search.createFilter({
            name: 'entity', // Assuming filtering by customer
            operator: search.Operator.IS,
            values: customerId 
        }));

        redirect.toSearch({ search: mySearch }); 
    }

    return { onRequest: onRequest }; 
}); 

Client-Script

function openFilteredSearch() { 
    var suiteletUrl = url.resolveScript({
        scriptId: 'custom_script', 
        deploymentId: 'custom_script_suietlet', 
        returnExternalUrl: true
    });

    suiteletUrl += '&intId=' + context.currentRecord.getValue('id');
    window.open(suiteletUrl, '_blank'); 
} 

Let Me Explain

The beauty of this method is the filter added within the Suitelet. This allows you to use one saved search that dynamically adapts its results based on the ID passed to it.

Key Points

  • You might need to adjust field names in the filter if you’re working with record types other than customers.
  • Ensure your Suitelet and client-script have appropriate permissions and deployments

Need Help? Let’s Connect!

I’m a certified NetSuite developer dedicated to making NetSuite work seamlessly for businesses. If you have any NetSuite development requirements, I’d be delighted to assist! Please feel free to reach out.

← Back

Thank you for your response. ✨

Warning
Warning
Warning
Warning.