System's data with SFCC Digital Script API


All requires we have seen in previous chapters of SFRA course that starts with dw/ means that are part of the Salesforce Commerce Cloud API. we don’t have access to the source code. In case you need details, functions, attributes about any of them, refer to the official documentation.

The use will them to access data about the system, such as: products, catalogs, prices, etc. You can access the API from both controllers and ISML templates for expressions or inside <isscript> tags.

DW Requires example

API Packages

The Digital Script API is organized in packages, just like Java. Unlike Java, inheritance is not possible from these classes or packages when you create a script. You can only use the properties and methods of these classes in your scripts.

In this API, the TopLevel package is the default package. It is similar to java.lang in Java. It does not need to be imported into scripts. It provides standard ECMAScript classes and extensions, such as: Error, Date, Function, String, Math, Number, XML.

The class contains many of the common constants and properties used in scripts. Some properties are: customer, request and session.

In these packages there are many classes that end with Mgr: These classes, for example, dw.catalog.ProductMgr, retrieves instances of business objects related to the package they belong to.

For example, use ProductMgr.getProduct(String id) to get a product using a unique identifier. The method returns a Product instance which you can use to find information about the product. This pattern is repeated for all Managers.

The table below shows the description of some of these packages. You don’t need to remember everything, just use it as a reference for future needs:

eCommerce API Packages Description
For campaign and promotions.
ClassesPromotionMgr, Campaign, Promotion, SourceCodeGroup, etc.
For catalog, product, and price book.
Classes: CatalogMgr, Category, Product, Recommendation, PriceBook, etc.
For non-product content management.
Classes: ContentMgr, Content, Folder, Library, etc.
For customer profile and account.
Classes: CustomerMgr, Customer, Profile, ProductList, OrderHistory, etc.
For orders, including: basket, coupons, line items, payment, shipment
Classes: Basket, Order, ProductLineItem, ShippingMgr, TaxMgr, etc.
Generic API Packages Description
Encryption services using JCA; DES, Triple-DES, AES, RSA, etc.
Classes: Cipher, MessageDigest
Input and output.
Classes: File, FileReader, CSVStreamReader, XMLStreamReader, etc.
System base classes and custom objects.
Classes: PersistentObject, ExtensibleObject, CustomObjectMgr, etc.
Web services related APIs.
Classes: WebReference, Stub
System functions.
Classes: Site, Request, Session, Logger
Similar to the java.util API: collections, maps and calendar classes.
Immutable value objects.
Classes: Money, Quantity
Classes: URLUtils, Forms, Cookie, HttpParameterMap, etc.

You can also embed SFCC Script API calls into ISML by using the <isset> tag as you can see below:

					<isset name="PaymentInst" value="${require('dw/order/PaymentInstrument');}" scope="page" />

Inside of the <isscript> tag, you can fully qualify every class you want to use or you can import any packages at the top of the script:

    var CatalogMgr = require('dw/catalog/CatalogMgr');
    var siteCatalog = CatalogMgr.getSiteCatalog();

Be aware, this practice of adding logic inside ISML templates is NOT RECOMMENDED, so use it with moderation. Instead, always try to add any logic in the Controller.

Digital Script API. Customer package

How to be a Certified Salesforce Commerce Cloud Developer for FREE

Unlock a FREE PDF with SFCC B2C Certification questions from our Udemy Course. Join our newsletter!
Check your email, you’ll receive a copy in a few seconds. If you don’t see it, please check your spam folder.

Do you like cookies? 🍪 We use cookies to ensure you get the best experience on our website. Learn more.