Highlighted

How can I convert a UDO variable from string to array?

Silver Contributor
Silver Contributor

I have a UDO variable populated as a list ("item1, item2, item3") and a Criteo tag needs to receive an array.

How can I convert this variable into array just for this tag?

Thanks!


Best regards,

6 REPLIES 6
Highlighted

How can I convert a UDO variable from string to array?

Tealium Employee

Hi Lluis,

You can used a scoped Set Data values extension. This means that any data transformation you perform in that extension will only exist within the scope of the selected tag.

Using the JS code input you can then do something like:

b['products'].split(',')

The b object is the current working object that contains all of the UDO. The split function will then create an array using the character defined as the separator.

Highlighted

How can I convert a UDO variable from string to array?

Tealium Employee

2014-09-29_1502.png

Highlighted

How can I convert a UDO variable from string to array?

Rookie Contributor

Is it possible to do the opposite (IE, convert an array to a string)? We have our product_sku variable as an array site-wide even when there's only one product and one vendor is taking issue with this and what's us to pass it as a string.

Highlighted

How can I convert a UDO variable from string to array?

Tealium Employee

Hi Jeremy,

The javascript for this is would be:

b['product_skus'].join('|')

The character being what you want to use to separate the entires (normally provided in the tags documentation). You would then scope this extension to just that tag so this modification would only take place in the scope of this tag and therefore would not affect your other tags.

Highlighted

How can I convert a UDO variable from string to array?

Rookie Contributor

Hi,
That didn't work. I've also tried the below variations of this code and they had the following results.

b.'product_skus'.join('|') = broke the container

b.product_skus.join('|') = still an array

Highlighted

How can I convert a UDO variable from string to array?

Tealium Employee

Hi Jeremy,

if you contact support we will be able to more efficiently help you with your request.

But I believe you issue was you missed the brackets off the first try but also I typed product_skus as an example and you mentioned product_sku in your message. So you would need to adjust for that.