Expand my Community achievements bar.

SOLVED

Mapping items from an array in Calculated Fields, within Data Collection > Data Streams on the edge network

Avatar

Level 1

Hi - I'm new to "Calculated Fields" and am struggling. I have a data layer that contains nested arrays. I'm trying to reduce client-side processing on the user browser by moving some of the processing server-side.

 

I can send the data layer event object to the web SDK. When I come to map the data stream, I can define incoming source data by providing my JSON schema object for the data layer (which contains arrays), but then when I come to the next screen, if I want to get a specific key value pair from the objects within the array, and then convert this into a concatenated string to return as a single data point, how is this achieved?

 

I imagine some combination of "map_get_values" and a version of toString("_") (which I can't locate) to turn the array returned by the map function into a string.

For example:

input = [{"name": "name1"},{"name": "name2"},{"name": "name3"},{"name": "name4"}];

 

How could I use map to return a value like this - "name1_name2_name3_name4"

 

In standard JS, it'd just be something like: return input.map(function(key){return key.name}).toString("_");

 

^^ and I'd be able to then pass the output directly to a variable of my choice.

How can the same be achieved in calculated fields? Does it have to map to another object within the schema, and then that is mapped, or can you simply return the output and map it directly?

 

Thanks

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @matt-loop-horizon 

 

Try using array data mapping functions or combination of functions in calculated fields like "to_array" and "split"

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

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @matt-loop-horizon 

 

Try using array data mapping functions or combination of functions in calculated fields like "to_array" and "split"

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

Avatar

Level 1

Hi @Sneha-Parmar - thanks, I'll give it a go.

Will it return a value UI can then map directly, or do I need to push the values returned to another object in my schema before I can map them? Thanks