netsuite Scripting searches with Filter Expressions Useful hints

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

  1. Here you can find the list of available search filter values for date fileds:
    https://system.netsuite.com/app/help/helpcenter.nl?fid=section_N3010842.html
    These you can use in expressions like:
['trandate', 'notbefore', 'daysAgo17']
  1. Here are the search operators:
    https://system.netsuite.com/app/help/helpcenter.nl?fid=section_N3005172.html
    Of course you can use serach.Operator enum:
    https://system.netsuite.com/app/help/helpcenter.nl?fid=section_4345782273.html

  2. Here are the search summary types:
    https://system.netsuite.com/app/help/helpcenter.nl?fid=section_N3010474.html

  3. You can use ANYOF operator only on select type fields (List/Record). If you want to use it against free-text fields (like names, emails etc.), the only way is to create a nested Filter Expression with 'OR' operators:

[ ['email', 'startswith', '[email protected]'],
  'or', ['email', 'startswith', '[email protected]'], 
  'or', ['email', 'startswith', '[email protected]'], 
  'or', ['email', 'startswith', '[email protected]'] 
]

or you can write small script, doing this instead of you:

function stringFieldAnyOf(fieldId, listOfValues) {    
    var result = [];
    if (listOfValues.length > 0) {
        for (var i = 0; i < listOfValues.length; i++) {
            result.push([fieldId, 'startswith', listOfValues[i]]);
            result.push('or');
        }
        result.pop(); // remove the last 'or'
    }
    return result;
}

// usage: (two more filters added just to illustrate how to combine with other filters)
var custSearch = search.create({
  type: record.Type.CUSTOMER,
  columns: searchColumn,
  filters: [
            ['companyname', 'startswith', 'A'], 
            'and', stringFieldAnyOf('email', ['[email protected]', '[email protected]']),
            'and', ['companyname', 'contains', 'b']
           ]

});
  1. Still not confident? Looking for a cheat? :)
    Create a saved search in the Netsuite UI, take the search ID (lets say: customsearch1234) and log.debug the filter expression:
    var s = search.load('customsearch1234');
    
    log.debug('filterExpression', JSON.stringify(s.filterExpression));


Got any netsuite Question?