Custom Attributes

Custom attributes and site preferences typed from your metadata XML, with completion, Cmd+Click to the definition and Find Usages in JetBrains IDEs

Intellij SFCC types the custom attributes of site preferences, products, orders, customers and every other system object from the metadata XML in your project, as the VS Code extension does

Custom attributes complete with their display name and the type B2C Commerce returns, and getCustomPreferenceValue returns the preference's type. Cmd+Click opens the attribute in the metadata XML, where Show Usages lists every script, template and attribute group that reads it

Before you start

NeedsWhy
Metadata XML in the projectAttributes come from system-objecttype-extensions.xml and any XML file in a meta or metadata folder, such as your site import data
A valid license or trialTypes, completion and navigation of custom attributes are paid features, see Purchase & License
Finished indexingWhile the IDE indexes, custom keeps its Script API type

Where attributes are typed

CodeAttributes of
Site.current.preferences.custom, Site.getCurrent().getPreferences().getCustom()SitePreferences
product.custom, product.getCustom()Product, for variants and variation groups too
order.custom, basket.custom, customer.profile.custom and any other customThe object's system type
A value typed with JSDoc, such as @param {dw.catalog.Product} productThe JSDoc type
An ISML <isset> variable that holds any of themThe same type, in every template that sees the variable

A name that the metadata doesn't declare keeps the Script API's type, so code that reads an attribute defined only on the instance still works

Attribute types

Each attribute has the type that B2C Commerce returns for its metadata type

Metadata typeType in code
string, text, password, emailstring
int, doublenumber
booleanboolean
date, datetimeDate
htmldw.content.MarkupText
imagedw.content.MediaFile
set-of-string, set-of-int, set-of-doublestring[] or number[]
enum-of-stringEnumValue<'express' | 'standard'>, with the values the definition lists
enum-of-intEnumValue<number>

An enum with select multiple is an array of EnumValue. Completion shows each attribute with the custom attribute icon , its display name and its type

Site preferences

Site.getCurrent().getCustomPreferenceValue('freeShippingThreshold') completes the preference IDs and returns the preference's type, here number. Cmd+Click on the ID opens its definition

To name a preference's type in JSDoc, use SitePreferenceOf

/** @type {SitePreferenceOf<'checkoutMode'>} */
var mode = Site.current.getCustomPreferenceValue('checkoutMode');

Go to the definition

Cmd+Click (Ctrl+Click) on an attribute in a member read, a custom['id'] string or a getCustomPreferenceValue('id') argument opens its attribute-id in the metadata XML. When several files define the attribute, a chooser lists them

Find Usages

Find Usages (Option+F7, Alt+F7) on an attribute-definition in the metadata XML, or on any read in code, lists:

  • Scripts and templates that read the attribute, as a member, a string or in an ISML expression
  • Attribute groups in the metadata XML that list it
  • Form fields bound to it with binding="custom.loyaltyEnabled" or attribute-def, see Forms

Custom attributes are named in Business Manager, so Rename is not offered for them

Custom objects

CodeCompletes
CustomObjectMgr.getCustomObject('...', key) and the other CustomObjectMgr methodsCustom object type IDs
.custom. on a custom objectAttributes of all custom object types, not filtered by type

Always current

Types follow your edits to the metadata XML, files changed on disk and branch switches at once, with no reindex and no restart. Changing only an attribute's type or its description updates completion and types too

Troubleshooting

ProblemFix
custom. lists no attributesCheck that the metadata XML is in the project under the names above, that indexing finished and that the plugin has a valid license or trial
No attributes on a valueGive the value its dw. type with JSDoc
An attribute has the wrong typeCheck its <type> in every metadata file that defines it. Cmd+Click lists them all

On this page