Scripts
B2C Commerce provides a proprietary scripting language that the server interprets and includes in storefront pages as JavaScript.
Only existing customers can access some of the links on this page. Visit Salesforce Commerce Cloud GitHub Repositories and Access for information about how to get access to the Commerce Cloud repositories.
B2C Commerce script supports data types that allow you to integrate extensive functionality into your scripts.
Attributes that are queryable can be found when using Advanced Search extended attributes when searching for products in Business Manager. Whether or not the data type is queryable in Business Manager doesn't affect whether the attribute is searchable in the storefront.
B2C Commerce supports the data types listed in the following table for B2C Commerce script.
Type | JavaScript Type | Description | Queryable in Business Manager? |
---|---|---|---|
String | B2C Commerce script top-level String class | Letters, numbers, and punctuation. Use for a word or sentence. Maximum 4000 bytes allowed. | Yes |
Text | B2C Commerce script top-level String class | Letters, numbers, and punctuation. Use for large amounts of text, such as descriptions. | No |
Html | B2C Commerce script dw.content.MarkupText class | HTML tags. This type is intended for HTML tags and values. If editing HTML attributes, Business Manager lets you edit them in an HTML editor. Editing in an HTML editor isn't possible for String or Text data types. | No |
Integer | number | A number without decimal places, such as 1, 2, 3, or 4. Attribute value range is from -2,147,483,648 to 2,147,483,647 (32 bit Signed Integer) | Yes |
Number | number | A floating point number with double precision. In terms of persistency or database, the supported values are zero as well as positive and negative fixed numbers with absolute values from 1.0E-130 to but not including 1.0E126. 'NaN', 'Infinity' and '-Infinity' are not supported. | Yes |
Boolean | boolean | True or False | Yes |
Date | B2C Commerce script top-level Date class | MM/dd/yyyy | Yes |
Date + Time | B2C Commerce script top-level Date class | MM/dd/yyyy : h: mm a | Yes |
Image | B2C Commerce script dw.content.MediaFile class | An image. Merchants can select the image from the image folder structure. Developers can use a script to dynamically retrieve an image using a pipeline. | No |
string | Email address. Business Manager requires the merchant to enter a valid syntax for an email address. For example, it requires a valid extension after the @ sign, among other requirements. | Yes | |
Password | string | Password. This type shows a masked field and confirmation field where the merchant can enter a password. Password data type values are encrypted on export and can be encrypted for import. | No |
Set of String | JavaScript array object containing string | The attribute value is zero or more strings. Use when you want the merchant to enter one or more strings. Sets don't contain duplicates. | Yes |
Set of Integer | JavaScript array object containing number | The attribute value is zero or more integers. Use when you want the merchant to enter one or more integers. Sets don't contain duplicates. | Yes |
Set of Number | JavaScript array object containing number | The attribute value is zero or more numbers. Use when you want the merchant to enter one or more numbers. Sets don't contain duplicates. | Yes |
Enum of String | B2C Commerce script dw.value.EnumValue class with value of type string, possibly in a JavaScript array object | The attribute value is zero or more strings. Use when you want the merchant to select one or more fixed values. Select Multiple if you want more than one value associated with the attribute. | Yes |
Enum of Integer | B2C Commerce script dw.value.EnumValue class with value of type number, possibly in a JavaScript array object | The attribute value is zero or more integers. Check the Multiple checkbox if you want more than one value associated with the attribute. | Yes |
We provide script timeouts to protect storefronts. For example, if you accidentally create an endless loop, the loop can cause massive thread exhaustion and require a restart of the instance.
The described rules apply fully for compatibility modes 21.2 and later. For older compatibility modes depending on the situation, a defined timeout may not be active.
Scripts in different contexts can have different timeouts (see the following tables). If a script is called from a different context then the resulting timeout is the one that ends earliest. For example, if shortly before the 5-minute timeout of a controller request a page designer script is started, then the page designer script can be aborted before its own 30-second timeout is finished.
Root Contexts | Timeout | Configurable |
---|---|---|
Controller Requests | 5 minutes | - |
OCAPI Requests Hooks | 30 seconds | - |
Script module step | - | Yes, see Steptypes.json Syntax. |
Embedded Contexts | Timeout | Configurable |
---|---|---|
Page Designer scripts | 30 seconds | - |
Form field validation scripts | 30 seconds | - |
Hooks called from scripts | - | - |
ISML embedded scripts | - | - |
Pipeline Contexts (deprecated) | Timeout | Configurable |
---|---|---|
Pipeline assigns node scripts | 30 seconds | - |
Eval pipelet | 30 seconds | - |
Script pipelet | 30 seconds within storefront requests and 15 minutes within jobs | Yes, see Pipelet Script. |
If a debug session is open, the minimum timeout for all script contexts is increased to 30 minutes.
In case a script timeout occurs the script is aborted with a non-catchable exception. The exception is logged in the error log. The message text contains something like:
Typically this error leads to an error response (HTTP status 500) or a failed job execution. Note if this happens during template rendering the request might not fail, instead, a partly rendered response might be seen by users, but such responses are never cached longer than 5 minutes.
Pipeline runtime is limited via the Quota “api.pipeline.timeout”. This defines a timeout of 5 minutes for storefront requests, and no timeout during job execution, for example, via the ExecutePipeline Job Step.
The rules for the script timeout always apply and aren’t influenced by the Quota “api.pipeline.timeout”.
The timeout values for SFTPClient
, HTTPClient
, and webreference
objects are based on the timeout value of the calling script. The script timeout value is used as an upper bound for the timeout that is configured for the SFTPClient
and HTTPClient
.
It’s recommended to use the service framework, which has multiple monitoring and management features for web services. Nevertheless, for HTTPClient or SFTPClient, the timeouts can also be set as part of the function call.
To view the default global timeout:
- Select Administration > Global Preferences > Global Timeouts.
If you’re having difficulty with scripts timing out while calling a third-party system or service, you can contact Customer Support to change the timeouts temporarily.
The Script Debugger API is a JSON-based set of requests and responses that are managed using a REST servlet.
This RESTful API enables you to create applications that interact with the Script Debugger for setting breakpoints, viewing variables, and evaluating expressions.
This API isn't available on a Production instance.