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
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 itBefore you start
| Needs | Why |
|---|---|
| Metadata XML in the project | Attributes 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 trial | Types, completion and navigation of custom attributes are paid features, see Purchase & License |
| Finished indexing | While the IDE indexes, custom keeps its Script API type |
Where attributes are typed
| Code | Attributes 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 custom | The object's system type |
A value typed with JSDoc, such as @param {dw.catalog.Product} product | The JSDoc type |
An ISML <isset> variable that holds any of them | The 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 type | Type in code |
|---|---|
string, text, password, email | string |
int, double | number |
boolean | boolean |
date, datetime | Date |
html | dw.content.MarkupText |
image | dw.content.MediaFile |
set-of-string, set-of-int, set-of-double | string[] or number[] |
enum-of-string | EnumValue<'express' | 'standard'>, with the values the definition lists |
enum-of-int | EnumValue<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"orattribute-def, see Forms
Custom attributes are named in Business Manager, so Rename is not offered for them
Custom objects
| Code | Completes |
|---|---|
CustomObjectMgr.getCustomObject('...', key) and the other CustomObjectMgr methods | Custom object type IDs |
.custom. on a custom object | Attributes 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
| Problem | Fix |
|---|---|
custom. lists no attributes | Check 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 value | Give the value its dw. type with JSDoc |
| An attribute has the wrong type | Check its <type> in every metadata file that defines it. Cmd+Click lists them all |