#17855 Score: 0

jmkplessers
  • Contributions: 0
  • Level 1

I have seen this when dynamically building search filter expressions. This bug only appears in server scripts. You can run the following code in the script debugger to demonstrate the error:

(I left some context in to show an actual use case for building the expression this way):

Code:
require([“N/search”], function(search) {
var dynamicValue = “foo”;
var filterExpr = [
“formulanumeric: case when regexp_like({memo}, ‘(^|\W)” + dynamicValue + “(\W|$)’) then 1 else 0 end”,
“equalto”,
“1”
];

log.debug({ title: typeof filterExpr[0] }); // string
log.debug({ title: typeof filterExpr[1] }); // string

// throws SSS_INVALID_SRCH_FILTER_EXPR_TYPE: Malformed search filter expression, first two elements must be strings.
search.create({
type: search.Type.SALES_ORDER,
filters: filterExpr,
});
});
Interestingly, NetSuite complains that the values are not strings when they clearly are.

My best guess is that the Rhino interpreter parses string concatenation expressions into different Java classes than string literals/variables. The NetSuite API then fails to consider those classes when validating that an argument is a javascript “string”.

As you have found, you can get around this by evaluating the string concatenation differently or before storing the variable:

Code:
// works
var filterExpr = [
[
“formulanumeric: case when regexp_like({memo}, ‘(^|\W)”,
dynamicValue,
“(\W|$)’) then 1 else 0 end”
].join(“”),
“equalto”,
“1”
];

Code:
// works
var filterExpr = [
String(“formulanumeric: case when regexp_like({memo}, ‘(^|\W)” + dynamicValue + “(\W|$)’) then 1 else 0 end”),
“equalto”,
“1”
];