Using the Custom SpEL resolve() Function

The custom SpEL resolve() function helps you manage and manipulate data in Data Hub.

General usage of the resolve() function is: resolve('<type_code>'[, '<pool_name>'][, 'integrationKey=<value>' | '<primary_key_attribute>=<value>',...]) where:
  • <type_code> is a type code of a CanonicalItem being referenced.
  • <pool_name> is the name of the data pool where the referenced object should exist. If pool name is not specified explicitly, then the referenced object resolves in the same data pool where the context object exists. If the context object is not an instance of a CanonicalItem, then the default GLOBAL pool is used if it is not specified in the expression.
  • integrationKey=<value> specifies the integration key value of the referenced item instead of deriving it implicitly from the expression context. As an alternative, you may specify values of all primary key attributes in the function call.

Examples

Using a Look Up Table for Reference

Load a named pool with a look up table containing country codes. Then, as you compose the raw items in another pool, you use the resolve() function to find a raw item's reference value in the look up table. For example, your raw items contain country names, but, once composed, reflect a country code instead. So your composition XML contains a transformation expression that uses a resolve function. The resolve function does a lookup of the country code from the named pool using the countryName attribute in the canonical XML as the base reference.

Another example, your look up table may help you assign a specific SAP Commerce Cloud catalog to a target item during publication. The assignment is done in your custom composition handler or in a Spring extension XML file.

Publishing Canonical Item Variants

This technique uses the resolve() function as a look up tool, and, while the technique is the same, the purpose is different.

When publishing a canonical item, you want to map it one-to-one to a target item. However, many canonical items have lots of variants, so one-to-one mapping requires some juggling. To accomplish the mapping, you use the resolve() function to look up each unique variant value, and then map it to a target item. For a detailed description of this process, see Publishing Canonical Item Variants.

Dereferencing During Publication

As part of transforming canonical attributes into target attributes during target system publication, the custom SpEL resolve() function may be used to dereference a canonical item. The extension logic looks at each field in each canonical record. It maps to each target item type attribute (found in the extension XML file definition of the target item). You use the resolve() function as part of the extension XML's transformation expression to look up the correct data element, see the following code snippet. For more information, see Using Extension XML to Transform Data.

XML Extension File
<attribute>                            
    <name>town</name>
    <localizable>false</localizable>
    <collection>false</collection>
    <transformationExpression>resolve('CanonicalAddress')?.city</transformationExpression>
    <exportCode>town</exportCode>
    <mandatoryInHeader>true</mandatoryInHeader>
</attribute>