why is this line giving me a suitescript syntax er...
# ask-stanley-ai
m
why is this line giving me a suitescript syntax error when using in a 2.1 script? const rmas = rrs.filter((rr) => rr.type === "Return Authorization");
c
AI generated answer (using internal Slack threads):
The line of code you provided is giving a SuiteScript syntax error when used in a 2.1 script because it uses a feature that is not available in SuiteScript 2.0, which is the version your NetSuite instance is set to parse. The feature in question is the use of template strings, which is a feature of ECMAScript 6 (ES6) and is not supported in SuiteScript 2.0. Here is the line of code you provided:
Copy code
const rmas = rrs.filter((rr) => rr.type === "Return Authorization");
In this line, you are using an arrow function and a template string, both of which are ES6 features. SuiteScript 2.0 is based on an earlier version of JavaScript (ECMAScript 5.1) and does not support these features. To resolve this issue, you can either rewrite your code to only use features supported by SuiteScript 2.0, or you can set your NetSuite instance to parse 2.x scripts as SuiteScript 2.1, which does support these features. To set your NetSuite instance to parse 2.x scripts as SuiteScript 2.1, you can follow these steps: 1. Go to Setup > Company > General Preferences. 2. Under the SuiteCloud tab, find the SuiteScript section. 3. Set the "Default Version for 2.x Scripts" to 2.1. 4. Click Save. Please note that changing this setting will affect all 2.x scripts in your NetSuite instance, so you should thoroughly test your scripts after making this change to ensure they still work as expected. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.813569427
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.811135828
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.808159292
Please provide your feedback on this answer.
a
That looks like valid 2.1 syntax to me. JSHint thinks so too (but only when ES6 features are turned on). In your script, ensure to specify @NApiVersion 2.1 instead of 2.x, unless you have NetSuite configured to use 2.1 when 2.x is specified.
1
m
Yeah it ended up 2.x did not like the arrow function syntax. Thanks for the suggestion though!
a
2.1 is fine with arrow syntax; I use it all the time. 2.x will be interpreted as 2.0 if your NetSuite is configured to do it that way though.