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:
- Create Your Saved Search: Build a saved search on the desired record type (e.g., customers). Initially, you don’t need any filters.
- 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.
- Takes an internal ID parameter from the URL (
- 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.
Thank you for your response. ✨
- AI for Business: Beyond the Buzz
- Clearing Up NetSuite Misconceptions: Async vs. Map/Reduce
- Converting NetSuite Reports to CSV: Strategies for NetSuite Developers
- Customizing the NetSuite Actions Menu for Enhanced Workflows
- DOM Manipulation: The NetSuite Developer’s (Sometimes) Secret Weapon
- Dynamically Hide Field Groups in NetSuite with Client-Side Scripts
- NetSuite Developers: The Good, The Bad, and The Notepad-Loving
- NetSuite Solutions: It Takes a Village (of Scripts)
- Streamline Your NetSuite Advanced PDF Templates with External Freemarker Files
- Understanding NetSuite User Event Entry Points: BeforeSubmit vs. afterSubmit
- Unlocking Efficiency with Async Functions in NetSuite Server-Side SuiteScript
- Why Your NetSuite Scripts Should Play Nicely: The Importance of Pre-Customization Analysis
