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
- Form fields bound to it with
binding="custom.loyaltyEnabled"orattribute-def, see Forms
Only reads of a value typed as the attribute's object count, so this.country in a constructor of your own is not a read of a country attribute
Custom attributes are named in Business Manager, so Rename is not offered for them
Usages in the metadata XML
| In the metadata XML | What it does |
|---|---|
3 usages after each attribute-definition | Opens the usages popup. Custom object keys have it too |
Cmd+Click (Ctrl+Click) on the attribute-id | Opens the same popup |
| A grey definition | Nothing in the project reads the attribute |
The counts follow your edits as you type. A read the plugin can't type, such as custom[name] with a variable or a value with no type, isn't counted, so check a grey attribute before you delete it
Turn the counts off in Settings › Editor › Inlay Hints › Code vision › SFCC Custom Attributes, and the grey in Settings › Editor › Inspections › SFCC › Metadata › Unused custom attribute
To add, change or remove attributes without writing the XML, open the file in the Metadata Editor
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 |