Class CustomAttributes
This class is used together with other classes that contain custom attributes and is used to read and write these attributes. The actual attributes are accessible as ECMA properties. The syntax for setting and retrieving the value of a custom attribute depends upon the type of the attribute. An exception will be thrown, if the wrong syntax is used to set an individual attribute.
The following script examples demonstrate how to work with custom attributes. Suppose we have an ExtensibleObject named "eo" possessing attributes of all the different types supported by the Commerce Cloud Digital metadata system. The following script snippet shows that setting single-valued attributes is simply a matter of using the assignment operator and standard ECMA primitives and built-in types:
Retrieving multi-value attributes and working with Java-backed arrays
Multi-value attributes return Java-backed arrays, which contain copies of the internal data. In contrast to native JavaScript arrays, a Java-backed array behaves differently in the following ways:
Array.isArray( javaBackedArray )will returnfalse. If you want to do something based on the value type, usejavaBackedArray instanceof Arrayinstead.- Adding to or removing elements from a Java-backed array is not supported. You need to create a new native JavaScript array based on the Java-backed array, e.g. with
Array.from( javaBackedArray )and do the modifications there.
Updating multi-value attributes
Retrieved data from a multi-value attribute returns a Java-backed array, which contains a copy of the internal data, so changes made to the Java-backed array do not affect the multi-value attribute. To update the multi-value attribute (e.g. adding a new element), it needs to be reassigned.
If you only want to change individual elements without appending or removing elements from the Java-backed array, you may even modify it directly.
Set-of attributes and enum-of attributes
Set-of attributes and enum-of attributes are handled in a very similar manner. The chief difference is that enum-of attributes are limited to a prescribed set of value definitions whereas set-of attributes are open-ended. Furthermore, each value in an enum-of attribute has a value and a display name which affects the retrieval logic.
For further details on the Commerce Cloud Digital attribute system, see the core Commerce Cloud Digital documentation.
This class does not have a constructor, so you cannot create it directly.
assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values