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.

TypeJavaScript TypeDescriptionQueryable in Business Manager?
StringB2C Commerce script top-level String classLetters, numbers, and punctuation. Use for a word or sentence. Maximum 4000 bytes allowed.Yes
TextB2C Commerce script top-level String classLetters, numbers, and punctuation. Use for large amounts of text, such as descriptions.No
HtmlB2C Commerce script dw.content.MarkupText classHTML 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
IntegernumberA 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
NumbernumberA 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
BooleanbooleanTrue or FalseYes
DateB2C Commerce script top-level Date classMM/dd/yyyyYes
Date + TimeB2C Commerce script top-level Date classMM/dd/yyyy : h: mm aYes
ImageB2C Commerce script dw.content.MediaFile classAn 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
EmailstringEmail 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
PasswordstringPassword. 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 StringJavaScript array object containing stringThe 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 IntegerJavaScript array object containing numberThe 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 NumberJavaScript array object containing numberThe 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 StringB2C Commerce script dw.value.EnumValue class with value of type string, possibly in a JavaScript array objectThe 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 IntegerB2C Commerce script dw.value.EnumValue class with value of type number, possibly in a JavaScript array objectThe 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 ContextsTimeoutConfigurable
Controller Requests5 minutes-
OCAPI Requests Hooks30 seconds-
Script module step-Yes, see Steptypes.json Syntax.
Embedded ContextsTimeoutConfigurable
Page Designer scripts30 seconds-
Form field validation scripts30 seconds-
Hooks called from scripts--
ISML embedded scripts--
Pipeline Contexts (deprecated)TimeoutConfigurable
Pipeline assigns node scripts30 seconds-
Eval pipelet30 seconds-
Script pipelet30 seconds within storefront requests and 15 minutes within jobsYes, 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:

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