Loading a search, adding to the filters. What's th...
# suitescript
n
Loading a search, adding to the filters. What's the trick to adding a set of "OR" I can push a searchFilter to the searchobj.filters but if I have an array of filters separated by "OR" it complains that a search filter was expected... [filter,"OR",filter etc etc etc]
b
Search.filterExpression is not the same thing as Search.filters
n
No I add an expression to the search,Filters just fine
Let me try again. essentially I want to do this:
Copy code
filters: [
        ['email', search.Operator.STARTSWITH, 'kwolff'],
        'and',
        [
            ['id', search.Operator.EQUALTO, 107], 'or',
            ['id',  search.Operator.EQUALTO, 2508]
        ]
    ]
but add that latter array with the 'or' separator to existing filters on a saved search
I have done this many times when I create a search but I want to extend an existing saved search as a base... which I also feel I've done many times but be blown if I can find an example 😉
b
same answer, use a filter expression instead of a filter
n
Right so not pushing this in to the saerchObj.filters?
Copy code
var imeifilterSingle = search.createFilter({
            name: 'name',
            operator: <http://search.Operator.IS|search.Operator.IS>,
            values:thisRow[cell],
        });
b
thats fine if you are pushiing to into saerchObj.filters
imeifilterSingle
is a filter
Copy code
[
        ['email', search.Operator.STARTSWITH, 'kwolff'],
        'and',
        [
            ['id', search.Operator.EQUALTO, 107], 'or',
            ['id',  search.Operator.EQUALTO, 2508]
        ]
    ]
is not a filter
n
ok Yes that's what I'm doing but I want an OR such I'm doing :
Copy code
someArray.push(imeifilterSingle);
someArray.push('or');
someArray.push(imeifilterDouble);
searchObj.filters.push(someArray);
And it's complaining about the "or";
where someArray is an array of search filters separated by "or"
b
This will be the third time I tell you to stop using
searchObj.filters
and to instead use
searchObj.filterExpression
n
OK I misunderstood for the 3rd time, gotcha, thanks for your time. 👍
Got there eventually thanks for your help 🤦‍♂️
m
I think some of the confusion is that NetSuite allows passing a filterExpression to filter param in search.create
👍 1
n
@michoel Thanks for replying. I've been doing this gig for 9 years now, but still get caught out from time to time with subtle things like this when I'm tired / juggling multiple tasks. I guess it's the price you pay for being human and not a robot! netsuite🤭