I was helped before with a search filter with a fo...
# suitescript
z
I was helped before with a search filter with a formula, but when I now try to push that into a search.load instead of a search.create, I am getting an invalid array argument error again. Any ideas?
Copy code
var formula = [
                        String("formulatext: CASE WHEN {name} IN (" + items + ") THEN 'T' ELSE 'F' END"),
                        "startswith",
                        "T"
                    ];
j
Can you show how you are passing it into an existing search? Netsuite implemented search.filterExpression as a getter/setter property, so it doesn't work if you call push on it directly
z
@jkabot I was just trying to push it to the filter array parentdata.filters.push(filter);
t
can you remove the String() ? It's not really adding any value there is it?
otherwise, try new String()
z
It still throws invalid array. The String() works if you are building the search in the script
j
Show the rest of the code
z
Untitled
j
There's a few problems
search.filters
is meant to be a list of "filter" objects. To define filters using nested arrays of strings, you need to use
search.filterExpression
instead. However,
search.filterExpression
is implemented in a funny way, and if you call push on it directly, it will not update the search. You need to reassign the value entirely.
Copy code
var formula = [ ... ];
var parentdata = search.load(...);

// copy filters
var expr = parentdata.filterExpression.slice();
// edit copy
expr.push('AND', formula);
// reassign filters
parentdata.filterExpression = expr;

var results = parentdata.run...
z
@jkabot Thanks, that looks like it does the job
👍 1