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:
1// attribute of value type 'Boolean'2eo.custom.bvalue = true;3var b : Boolean = eo.custom.bvalue;45// attribute of value type 'Integer'6eo.custom.ivalue = 10;7var i : Number = eo.custom.ivalue;89// attribute of value type 'Number'10eo.custom.dvalue = 99.99;11var d : Number = eo.custom.dvalue;1213// attribute of value type 'String'14eo.custom.svalue = "String1";15var s : String = eo.custom.svalue;1617// attribute of value type 'Email'18eo.custom.emailvalue = "email@demandware.com";19var e : String = eo.custom.emailvalue;2021// attribute of value type 'Text'22eo.custom.tvalue = "laaaaaaaaaaaarge text";23var t : String = eo.custom.tvalue;2425// attribute of value type 'Date'26eo.custom.dtvalue = new Date;27var date : Date = eo.custom.dtvalue;
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 return false. If you want to do something based on the value type, use javaBackedArray 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.
1var setofstring : Array = eo.custom.setofstringvalue;2if( Array.isArray( setofstring ) ) // returns false3{4 // this will never be reached, since setofstring is a Java-backed array and not a native JavaScript array5}6if( setofstring instanceof Array ) // returns true7{8 // this will be reached, since setofstring is a Java-backed array9}
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.
1// retrieve a Java-backed array and convert it to a native JavaScript array2var setofstring : Array = eo.custom.setofstringvalue;3var newValue = Array.from( setofstring );45// add new element6newValue.append( "new element" );78// reassign the new array to the multi-value attribute to persist the change9eo.custom.setofstringvalue = newValue;
If you only want to change individual elements without appending or removing elements from the Java-backed array, you
may even modify it directly.
1// retrieve a Java-backed array2var setofstring : Array = eo.custom.setofstringvalue;34// change individual element5setofstring[0] = "updated element";67// reassign the array to the multi-value attribute to persist the change8eo.custom.setofstringvalue = setofstring;
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.
1// attribute of value type 'Set of String'2// set the attribute value only if it hasn't been already set3if( !('setofstringvalue' in eo.custom) )4{5 eo.custom.setofstringvalue = new Array("abc","def","ghi");6}78// returns an Array of String instances9var setofstring : Array = eo.custom.setofstringvalue;10var s1 : String = setofstring[0];11var s2 : String = setofstring[1];12var s3 : String = setofstring[2];1314// attribute of value type 'Enum of Integer' with multi-value handling15eo.custom.enumofintmultivalue = new Array(1, 2, 3);1617// returns an Array of EnumValue instances18var enumofintmulti : Array = eo.custom.enumofintmultivalue;19var value1 : Number = enumofintmulti[0].getValue();20var displayvalue1 : String = enumofintmulti[0].getDisplayValue();21var value2 : Number = enumofintmulti[1].getValue();22var displayvalue2 : String = enumofintmulti[1].getDisplayValue();23var value3 : Number = enumofintmulti[2].getValue();24var displayvalue3 : String = enumofintmulti[2].getDisplayValue();
For further details on the Commerce Cloud Digital attribute system, see the core Commerce Cloud Digital
documentation.
Constructor Summary
This class does not have a constructor, so you cannot create it directly.