Enabling SuiteScript 2.1 at the Account Level
When you use the @NApiVersion JSDoc tag in a script file, you can specify a value of 2.x. This value usually represents the latest version of SuiteScript that is generally available. However, in this release, this value represents SuiteScript 2.0 by default. You can use the Execute SuiteScript 2.x Server Scripts As account-level preference to specify that the 2.x value should represent SuiteScript 2.1 instead of SuiteScript 2.0. Setting this preference to 2.1 applies to all scripts in your account that use the 2.x value. Scripts that use the 2.0 or 2.1 value for the @NApiVersion JSDoc tag are not affected. In other words, this preference doesn't affect scripts that specify 2.0 or 2.1 directly in the @NApiVersion tag.
You can use the Execute SuiteScript 2.x Server Scripts As preference to test how your SuiteScript 2.x scripts will execute using SuiteScript 2.1. This is helpful if you want to test all of your 2.x scripts as SuiteScript 2.1 scripts without having to specifically annotate each script with the @NApiVersion JSDoc tag value of 2.1. Using this preference, you don't need to change any script files to switch the SuiteScript version they execute as.
To enable SuiteScript 2.1 at the account level:
-
Go to Setup > Company > Preferences > General Preferences.
-
In the Execute SuiteScript 2.x Server Scripts As dropdown list, select 2.1.
-
Click Save.
When you use this account-level preference, you should be understand how validation of the script occurs. If you have a SuiteScript annotated as @NApiVersion 2.x and you set the Execute SuiteScript 2.x Server Scripts As preference to 2.1, syntax of the script is validated as if the script was a SuiteScript 2.0 script. If you add syntax that is supported only in SuiteScript 2.1, you receive a syntax error when you upload the script file.
This approach is designed to ensure that SuiteScript 2.x scripts in your account continue to work even if the Execute SuiteScript 2.x Server Scripts As preference is changed from 2.1 back to 2.0. To test new SuiteScript 2.1 features and syntax, you should update the @NApiVersion JSDoc tag in your script files from 2.x to 2.1 explicitly. You can also upload new scripts as SuiteScript 2.1 scripts.
The following table summarizes when errors can occur with SuiteScript 2.1 scripts:
Scenario |
Outcome |
---|---|
|
A syntax error occurs when you save the script. You can't save a script where you have added SuiteScript 2.1 syntax even if the Execute SuiteScript 2.x Server Scripts As preference is set to 2.1. To resolve this issue, change the @NApiVersion value to 2.1 to explicitly execute the script as a SuiteScript 2.1 script. |
|
The script no longer works. When the account-level preference is set to SuiteScript 2.0, all 2.x scripts execute as SuiteScript 2.0 scripts. SuiteScript 2.1 syntax is not valid in a SuiteScript 2.0 script. To resolve this issue, do one of the following:
|
The following table compares how you can use 2.0 or 2.1 syntax, set the @NApiVersion JSDoc tag, and choose the Execute SuiteScript 2.x Server Scripts As preference.
Syntax |
@ |
Execute SuiteScript 2.x Server Scripts As preference |
Upload the script file |
Create a script record |
Deploy the script |
Execute the script |
---|---|---|---|---|---|---|
2.0 |
2.0 |
2.0 |
Success |
Success |
Success. Script deployment is not affected by SuiteScript syntax, @NApiVersion value or preference setting. |
Success |
2.1 |
Success |
Success |
Success |
|||
2.1 |
2.0 |
Success |
Success |
Success |
||
2.1 |
Success |
Success |
Success |
|||
2.x |
2.0 |
Success |
Success |
Success |
||
2.1 |
Success |
Success |
Success |
|||
2.1 |
2.0 |
2.0 |
Syntax error |
The script file can’t be uploaded, therefore, a script record can't be created. |
The script file can't be uploaded, therefore, it can't be executed. |
|
2.1 |
Syntax error |
The script file can’t be uploaded, therefore, a script record can't be created. |
The script file can't be uploaded, therefore, it can't be executed. |
|||
2.1 |
2.0 |
Success |
Success |
Unsuccessful — type of error will vary |
||
2.1 |
Success |
Success |
Success |
|||
2.x |
2.0 |
Syntax error |
The script file can’t be uploaded, therefore, a script record can't be created. |
The script file can't be uploaded, therefore, it can't be executed. |
||
2.1 |
Syntax error |
The script file can’t be uploaded, therefore, a script record can't be created. |
The script file can't be uploaded, therefore, it can't be executed. |
You can check which version of SuiteScript is used to execute your script by looking at the Execute As Version field on the script record. For more information, see Version Information on the Script Record.
Version Information on the Script Record
Using the SuiteScript 2.1 value for the Execute SuiteScript 2.x Server Scripts As preference overrides the script version specified using the @NApiVersion
JSDoc tag within the script. Because of this, it can be useful to verify the version of SuiteScript used to execute the script. The script record includes two fields that provide information about SuiteScript version:
-
API Version — This field indicates the version of SuiteScript that is specified in the script file. It always shows a specific version of SuiteScript. For example, if you specify a version of 2.x in the script file, the value of this field is set to 2.0 (the value that the 2.x value maps to in this release by default). For more information about this field, see Script Record Creation.
-
Execute As Version — This field indicates the version of SuiteScript that is being used to execute the script. This field is only shown on the script record if the Execute SuiteScript 2.x Server Scripts As preference is set to 2.1, and is the only indication that the script is executed as a SuiteScript 2.1 script based on the Execute SuiteScript 2.x Server Scripts As preference. The original SuiteScript version (as indicated in the API Version field) is displayed when the script is listed in NetSuite (for example, in script lists, script deployment lists, scripted records lists, and so on).