Localization Context Filtering for SuiteScript 2.x
Since 2020.1, you can define the localization context in which a client or user event script can execute. Localization context filtering allows you to execute a script based on the country associated with the active record or transaction and prevents scripts from executing unnecessarily. For a list of records and transactions that support localization, see Records that Support Localization Context.
You can specify the execution order of localized client and user event scripts. A maximum of 10 localized/non-localized client scripts are supported. For more information, see The Scripted Records Page.
The system automatically determines the localization context for records and transactions based on their values for country fields such as subsidiary and tax nexus. It is important to understand this determination before you set up localization context filtering for scripts. For details, see Determining the Localization Context.
The localization context feature includes:
-
Localization Context Field - The Localization Context field on the Context Filtering tab has been added to the script deployment record. This field lists the countries for which the script is relevant. All countries are selected by default. When this field is set to a value other than the default, the script runs only on records associated with the selected country or countries, based on records’ localization context.
-
Entry Points for Client Scripts -There are two new entry points for SuiteScript 2.0 client scripts. These entry points are required to use localization context filtering in client scripts. localizationContextEnter(scriptContext) is executed when the record enters the localization context that is specified on the script deployment record. localizationContextExit(scriptContext) is executed when the record exits that context.
-
Locale Parameter -
scriptContext.locale
is a new parameter for the localizationContextEnter(scriptContext) and localizationContextExit(scriptContext) entry points. This parameter lists the countries representing the new localization context.
The following table shows how you can specify the localization context based on the script type.
Script Type |
Defining Localization Context Filtering |
SuiteScript 2.0 Client Script Type |
Complete the following steps to add localization context filtering to client scripts:
|
SuiteScript 2.0 User Event Script Type |
Define the localization context on the Context Filtering tab on the script deployment record only. For more information, see Localization Context. |
If a script deployment is localized on the Context Filtering tab, the pageInit
entry point of the script is ignored, and no other entry points of the script are called before localizationContextEnter
or after localizationContextExit
. It is possible that the record may never enter a localization context. In this case, no callbacks of the script are executed. For more information, see SuiteScript 2.x Client Script Entry Points and API.