object only partially available in delivery body within a workflow

Avatar

Avatar

guillermoL

Avatar

guillermoL

guillermoL

28-08-2017

Hi,

I am using the object targetData in a delivery of a workflow. If I try to see what's inside this object with the following code:

document.write("<pre>" + JSON.stringify(targetData) + "</pre>");

I only get part of the object, not all the keys that are available.

However, the keys are perfectly available as if I show them in the way:

document.write(targetData.keyName) 

And the interesting thing is that from that moment, and for any subsequent run, the key keyName is also shown in the JSON.stringify output that I mentioned above.

So, in other words, it looks like JSON.stringify(targetData) don't return anything initially on the first run, but as you start calling the individual parts of the object, then these are available to the JSON.stringify(targetData) for subsequent runs.

I have not only experienced this with JSON.stringify(targetData), but also by calling the value of the object as targetData["keyName"] . This would return undefined unless you have called before (even in a previous run) targetData.keyName.

That behaviour is looking very weird to me!

Anyone can figure out what is happening here?

Thanks in advance

Guillermo

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Amit_Kumar

MVP

Avatar

Amit_Kumar

MVP

Amit_Kumar
MVP

30-08-2017

Hi Guillermo,

object.key and object[key] accomplish the same thing, but Adobe campaign treats them differently.
When you use the object.Key this works because this is hardwired as you are loading only one attribute not all. If you have to This is designed in this way read data from xml when you need it, it is more of on demand system. It is handy when we interact with broadlog(big table, lots of attributes), it loads only part which we need.

If you compare two standards for  Object.keys ( O ) implementation, its algorithm is improved a lot over time

ECMAScript Language Specification - ECMA-262 Edition 5.1

ECMAScript® 2018 Language Specification

If you have loaded the data using additional data, then It should be fixed now. If not, may be you can raise a ticket with Adobe for this?

Regards,

Amit

Answers (4)

Answers (4)

Avatar

Avatar

Amit_Kumar

MVP

Avatar

Amit_Kumar

MVP

Amit_Kumar
MVP

28-08-2017

Guillermo, data is there but it's not loaded in the scope(xml) until you explicitly call it. If you are loading all the required attributes using additional data, then it will be available in XML scope.

Regards,

Amit

Avatar

Avatar

guillermoL

Avatar

guillermoL

guillermoL

29-08-2017

Thanks again Amit,

I'm sorry but I don't fully get it. Maybe I have not explained myself properly. I think I have actually loaded the additional data on a enrichment I am using.

The thing is that, from what I know, in javascript it is equivalent to access to an object in the way object.key or object['key'] . I still struggle to understand how can it be that I can use the first and not the second way. And what looks even more weird to me: once I access a value the first way (just assign the value to another variable, or just send it with a document.write ) , I can then freely use both ways. And from that moment, I can even use it both ways in subsequent runs of the workflow without having to use the first way first.

Does it make more sense?

Regards

Guillermo

Avatar

Avatar

guillermoL

Avatar

guillermoL

guillermoL

28-08-2017

Thanks for your reply Amit,

I am not sure this is the case. The data is indeed there. It's coming from a data enrichment, and I can always read and use it by using targetData.keyName.

Thanks

Guillermo

Avatar

Avatar

Amit_Kumar

MVP

Avatar

Amit_Kumar

MVP

Amit_Kumar
MVP

28-08-2017

Hi Guillermo,

This is happening because your key value is not available explicitly in targetData. If you want this to work load your keyname using additional data(Additional data ) in the query then this will be available in stringify.

Regards,

Amit