Expand my Community achievements bar.

Data Prep - Ability to use array notation ([*]) in calculated field

Avatar

Level 2

I am running into a problem when trying to use array notation ([*]) when using Data Prep mapping functions from within a calculated field.  

 

Taken from https://experienceleague.adobe.com/docs/experience-platform/datastreams/data-prep.html?lang=en :

jinx0011_0-1706138466023.png

 

This works fine if both the source and target contain array structures for the data (i.e. a simple mapping).  The only way I can get the same notation to work in a calculated field, again, relies on the source being in an array structure first (e.g., ${data.page.products[*].name} works fine in a calculated field as this represents a field name).

 

However, another use case is converting an input string containing delimiters into an object array structure on the target side.  While there are Data Prep mapping functions that can be used to convert an input string into an array (split, explode, add_to_array, etc.), I cannot seem to create a calculated field that uses Data Prep mapping functions while still retaining the ability to use array notation.  When I try to do so, I get the red exclamation point indicating I've typed in an invalid function.

 

The "Tip" in the screenshot above is interesting as it shows an example of mapping into the productListItems array structure.  This brings to mind the Adobe Analytics products string, which can contain many products, each containing different bits of information related to the product (a category, a name, quantity, price, zero or more events, zero or more eVars).  Each part of the products string might map into different fields within an object array target schema - so, for example the Product Category might go into productListItems[*].category, the Product Name into productListItems[*].name, and so on.  Again, there can be many products in the input string, so it would seem some ability to combine data prep mapping functions and array notation would be essential to map each product's information into the productListItems array structure.

 

Imagine trying to transform the following input string, which contains 3 products, into a XDM object array schema that contains different fields for product category, name, quantity, unit price, various custom events/dimensions:

productCategory1;productNameA;1;2.34;event1=1|event2=2;eVar1=abc|eVar2=def,productCategory2;productNameB;1;5.67;event1=1|event3=100;eVar1=lmnop|eVar3=itsgettingcomplex|eVar99=amiright,productCategory1;productNameC;1;10;;eVar100=ohno-notanotherproduct

 

In Data Prep, you might try to split the input string into an array and then use other functions to get the specific bit of data you want to map into a field. 

 

So, for productListItems[*].name (the second index in each product in the input string), maybe the function you'd want to write is:

to_array(false, explode(split(inputProductsString, ",")[*]), ";")[2])  <----this won't save in Data Prep because of [*], though [0] does get the first product, [1] gets the second product, and [2] gets the third

 

Other fields might involve more complex Data Prep mapping trickery to get the right value (e.g. one of the custom events/evars).  This might be an extreme example, but there could be others where the input string represents an array of things and we need to use Data Prep mapping functions to transform the data...and do so for each "index" in the input string.

 

Has anyone had any luck using Data Prep mapping functions along with [*] notation in a calculated field (or perhaps another clever way to handle this scenario)? 

 

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Reply