SuiteScript 2.0 Error: SSS_INVALID_SRCH_FILTER_EXPR_TYPE-CarlZeng

Issue: a search throw error SSS_INVALID_SRCH_FILTER_EXPR_TYPE Malformed search filter expression, first two elements must be strings. Sample code that

Issue: a search throw error SSS_INVALID_SRCH_FILTER_EXPR_TYPE 

Malformed search filter expression, first two elements must be strings. 

Sample code that causing error: 

var strFormulaNumeric = ‘CASE {custrecord_abc_id}’; for (var i = 0; i < this.arrPriceTblId.length; i++) {

 strFormulaNumeric += ' WHEN \\'' + this.arrPriceTblId\[i\] \+ '\\' THEN ' + (i + 1);

}
strFormulaNumeric += ' ELSE 0 END';

… var arrColumns = [];

arrColumns.push(search.createColumn({

 name : 'formulanumeric',

 formula : strFormulaNumeric,

 sort : search.Sort.DESC

}));

… var strFormulaFilter = ‘formulanumeric:’ + strFormulaNumeric; var arrFilters = [
[ ‘isinactive’, ‘is’, ‘F’ ], ‘AND’,
[ strFormulaFilter,
search.Operator.GREATERTHAN, 0 ] ];

Solution:

var arrFilters = [
[ ‘isinactive’, ‘is’, ‘F’ ], ‘AND’,
[ String(strFormulaFilter),
search.Operator.GREATERTHAN, 0 ] ];

We convert strFormulaFilter to a string again in JS, that works great :)

Great Idea:

When we have formula in the column, we sort it well; it’s the best way to roll out data as specific reqirement;  works perfect :-)

Thanks site: 

Notes from: 

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”.

https://netsuitehub.com/forums/reply/re-record-getvalue-errors-if-field-name-is-built-programatically-5/

https://www.flowinglink.com/suitescript-2-0-sss\_invalid\_srch\_filter\_expr\_type/