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 an account-level preference, Execute SuiteScript 2.x Server Scripts As, 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. Any scripts that use the 2.0 or 2.1 value for the @NApiVersion JSDoc tag are not affected. In other words, the value of the preference has no affect on scripts that specify a specific version (2.0 or 2.1) in the @NApiVersion JSDoc 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 approach is useful if you want to test all of the 2.x scripts in your account 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 do not need to alter any script files to change the SuiteScript version they use to execute.

To enable SuiteScript 2.1 at the account level:

  1. Go to Setup > Company > Preferences > General Preferences.

  2. In the Execute SuiteScript 2.x Server Scripts As dropdown list, select 2.1.

    Execute SuiteScript 2.X Server Scripts setting set to 2.1.
  3. Click Save.

When you use this account-level preference, you should be aware of how validation of the script occurs.

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

  1. Set the Execute SuiteScript 2.x Server Scripts As preference to 2.1.

  2. Open the script record of an executing script in your account that uses an @NApiVersion value of 2.x.

  3. Edit the script and add code that is supported only in SuiteScript 2.1 (such as using the Spread operator).

  4. Save the updated script.

A syntax error occurs when you save the script. You cannot add SuiteScript 2.1 syntax to existing 2.x scripts, 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.

  1. Upload a script that includes an @NApiVersion value of 2.x and also includes SuiteScript 2.1 syntax (such as using the Spread operator).

  2. Change the value of the Execute SuiteScript 2.1 Server Scripts As preference to 2.0.

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. You cannot include SuiteScript 2.1 syntax in a SuiteScript 2.0 script.

To resolve this issue, do one of the following:

  • Change the @NApiVersion value to 2.1 to explicitly execute the script as a SuiteScript 2.1 script.

  • Remove the SuiteScript 2.1 syntax from the script.

The following table provides a comparison of each way you can use 2.0 or 2.1 syntax, specify the @NApiVersion JSDoc tag, and set the Execute SuiteScript 2.x Server Scripts As perference value.

Syntax

@NApiVersion

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 verify the version of SuiteScript used to execute a script by checking 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 represents a concrete 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). For more information about this field, see Script Record Creation.

    Script's API Version setting set to 2.0.
  • Execute As Version — This field indicates the version of SuiteScript that is being used to execute the script. This field only appears 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).

    Scripts Execute As Version setting set to 2.1.

Related Topics

Executing a Single Script Using SuiteScript 2.1
Executing Scripts Using SuiteScript 2.1

General Notices