This topic contains 5 replies, has 0 voices, and was last updated by jmkplessers 6 years, 8 months ago.
-
AuthorPosts
-
October 30, 2017 at 12:42 pm #17848
starlingMarkI am iterating over a bunch of fields that are similarly named – one per month. If I do this:
Code:
currentRecord.getValue({ fieldId: ‘custrecord_myrecord_’ + month + ‘_quantity’ })
I get SSS_MISSING_REQD_ARGUMENT. If I build the field id name in a variable first, and then try this, I still get SSS_MISSING_REQD_ARGUMENT. However, if I do this craziness:Code:
currentRecord.getValue({ fieldId: eval(‘”‘ + ‘custrecord_myrecord_’ + month + ‘_quantity’ + ‘”‘) })
It works as expected. Am I missing something here?
This is a cached copy. Click here to see the original post. -
October 30, 2017 at 1:18 pm #17849
JohnCColeNot that I have a solution but I have had a similar issue in SuiteScript 1.0. building dynamic search filters. The same code would actually work on the client side but on the server side I had to use concat method as + operator was introducing an error maybe try
Code:
‘custrecord_myrecord_’.concat(month, ‘_quantity’) -
October 30, 2017 at 1:21 pm #17850
darrenhillconsultingI do this, no issues. I did notice, your first example ends with _quantity were as your second example ends in _qty
Perhaps that’s the real problem
starlingMark replied on 10/31/2017, 07:06 AM: Thanks Darren – fat fingering my examples is a bad way to start. No doubt the real issue lies between my keyboard and the user!
-
October 30, 2017 at 3:12 pm #17851
pcutlerI haven’t run into that issue myself, but if I was struggling with it my next step would be to edit the script to put the field name into a variable and log the value in that variable prior to invoking currentRecord.getValue.
-
March 4, 2018 at 12:00 pm #17852
starlingMarkI’ve actually hit my head on this again, but found another solution. For those that come after me, here’s an example.
If I call currentRecord.getValue({ fieldId: myField }) under the following circumstances, here is what happens:
myField = ‘custrecord_myfield’
worksmyField = ‘custrecord_’ + ‘myfield’
worksfieldName = ‘myfield’, myField = ‘custrecord_’ + fieldName
failsfieldName = ‘myfield’, myField = String(‘custrecord_’ + fieldName)
worksI cannot explain why this works, I just know that it does.
-
March 12, 2018 at 11:45 am #17855
jmkplessersI 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”
]; -
AuthorPosts
You must be logged in to reply to this topic.