A client script with @NApiVersion 2.x can't be dep...
# suitescript
b
A client script with @NApiVersion 2.x can't be deployed. The deploy fails with the message "An error occurred during custom object creation. Details: SuiteScript 2.x entry point scripts must implement one script type function.". Successive trial and error results in a stub of the script with just do-nothing versions of its entry points, which deploys successfully. Adding back the previous contents bit by bit to determine the cause results in the original contents deploying and running succesfully! Renaming the file or trying to deploy the SDF project to a different system results in the entry point error again. And again, deploying a stub first allows the full script to be deployed. So, the script itself is demonstrably valid because it functions fine if a stub is deployed to establish a trail for it, but it cannot be deployed directly. Can anyone here guess the cause of the deployment error?
e
A guess would be that you're writing 2.1, but the account setting is such that 2.x is interpreted as 2.0, so the module is not being parsed correctly. Stripping the code back to the stub removes any offending syntax, thus it parses correctly. I always advise folks to avoid
2.x
, and to be explicit about the version they're writing, especially if the code is being distributed to multiple environments where 2.x is never guaranteed to be interpreted the same. Share the stub and the full versions for better analysis.
b
You are correct about the cause. It was actually a few
let
statements in the script. The target system is configured to treat 2.x as 2.1, for what that's worth Setting the script version to 2.1 allowed the script to deploy with the
let
statements, so that at least was nice. I still have a bit of PTSD from the one time I deployed a 2.1 script, someone subsequently enabled SuiteTax in that account which was incompatible and caused all 2.1 scripts in that system to crash. Hopefully that's fixed now that SuiteTax is enabled by default. If I intend to write 2.0 and specify 2.0, but accidentally stray out of bounds and use something like a
let
statement, it sure would be nice if the error message referred to language or syntax in some way. That would have saved me about 12 hours of trial and error. Playing with the version might provide a useful data point for people -- when you get a nonsense error message, try specifying 2.1 and if that makes it go away you should try to make your script look more old fashioned. The script editor in the NetSuite UI does indicate "Syntax error: missing ; before statement" when you try to use a
let
statement in a script that's marked 2.0. It doesn't tell you what line the error is on, though, so it isn't that much more useful.