How to add 2 conditions in 'new nlobjSearchFilter'?

510 views Asked by At

My code is like that:

var filters = new Array();

        filters[0] = new nlobjSearchFilter("isperson", "customer", "is", "F")

        filters[1] =  new nlobjSearchFilter([["minimumquantity", "equalto", "0"], "OR", ["minimumquantity", "isempty", ""]]);

        
        if (customerId) filters.push(new nlobjSearchFilter("customer", null, "anyof", customerId));
        if (currency) filters.push(new nlobjSearchFilter("currency", null, "anyof", currency)); 

My question is how do I make filters[1] works with the 'OR' operator?

1

There are 1 answers

0
Mike Robbins On

You were on the right track with the 'or' condition.

I can't tell which record you're trying to query, but the easiest way to control multiple and/or conditions when building a search is to use search "filter expressions" rather than manually building with nlobjSearchFilter().

If you want to continue using nlobjSearchFilter(), look up how to use the .setLeftParens()/.setRightParens() and .setOr() functions (example). They're not documented in the NetSuite help).

var filters = [
    // this is how joins are referenced in filter expressions
    // this is equivalent to nlobjSearchFilter('isperson', 'customer', 'is', 'F')
    ['customer.isperson', 'is', 'F'],
    'and', [
        ['minimumquantity', 'equalto', 0], 'or', ['minimumquantity', 'isempty', null]
    ],
];

if (customerId) filters.push('and', ['customer', 'anyof', customerId]);
if (currencyId) filters.push('and', ['currency', 'anyof', currency]);