NetSuiteBytes

SuiteScript 2.0 Search Best Practices

When working with large datasets in NetSuite, search performance is critical...

Creating Efficient Searches

/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */
define(['N/search'], (search) => {
    function afterSubmit(context) {
        const customerSearch = search.create({
            type: search.Type.CUSTOMER,
            filters: [
                ['email', 'isnotempty', ''],
                'AND',
                ['status', 'anyof', '13'] // Active customers
            ],
            columns: [
                'entityid',
                'email',
                'phone'
            ]
        });
        
        // Process results efficiently
        customerSearch.run().each((result) => {
            // Your logic here
            return true; // Continue to next result
        });
    }
    
    return { afterSubmit };
});

💡 Pro Tip

Always limit your search columns to only what you need. Fetching unnecessary fields impacts performance.

⚠️ Important

Searches in User Event scripts can cause governance issues. Consider using Scheduled Scripts for large operations.

Performance Considerations

Method Governance Units Best Use Case
search.create() 10 Complex filtering
search.load() 5 Saved searches
search.lookupFields() 1 Single record field lookup