Hi all,
in this interface in AEPabout datastream mapping:
I'm trying to have a IF THEN ELSE condition. My goal is to have the value of data.pageUrl mapped to prop5 only if xdm.eventType = web.webPageDetails.pageViews
So I created a calculated field with the condition
iif(${xdm.eventType}.equals("web.webPageDetails.pageViews"),${data.pageUrl},nullify())
But the output is not working as expected: not only the field mapped (prop5) is null, multiple others attributes also inherit of this. They are empty.
So I try by adapting the function:
iif(${xdm.eventType}.equals("web.webPageDetails.pageViews"),${data.pageUrl},"")
iif(${xdm.eventType}.equals("web.webPageDetails.pageViews"),${data.pageUrl},null)
iif(${xdm.eventType} == "web.webPageDetails.pageViews",${data.pageUrl},nullify())
Do you have any idea of the reason of this? According to the doc, it should only impact the target field....
Does one of you also need to play with a if-then-else condition?
Thanks in advance
Robin
Views
Replies
Total Likes
I did an extra test with the following condition:
iif(${xdm.eventType}.equals("web.webPageDetails.pageViews"),"true","false")
The target field is the prop5 of Adobe analytics.
As result in Adobe Analytics I have this:
So the condition is working when it's true but nothing about the false ....
Is the IIF different than the IF ?
I've had similar issues, where "", null, and nullify() all throw errors (eg, The source field iif(xdm.web.webPageDetails.name.equals("Subscribe"),1,"") is null or not found) when the condition isn't matched. BUT... for me it has only ever affected that field. The errors don't seem to affect anything, really, they're just annoying when doing validation in the debugger or in assurance.
These have worked for me (I find things have worked better for me without the $ and curly brackets, though I can hardly claim to know why or recommend it as a best practice):
iif(xdm.eventType.equals("articleComplete"),1,"")
iif(matches_regex(xdm.web.webPageDetails._tenantID.attributes.articlePrimaryTopic,".*"),xdm.web.webPageDetails._tenantID.attributes.articlePrimaryTopic,xdm._tenantID.users.profile.events.topicFollowed)
...Other than they cause the seemingly-harmless error I mentioned before. Is that error ("Source field is null or not found") what you are getting?
Hi @robinl39529461 ,
The logic you are using is missing an additional check for cases where xdm.eventType = web.webPageDetails.pageViews but data.pageUrl does not exist, in this case the logic will work but still return a null in true case.
To fix this you need to first check if the source field contains any value and then run the remaining logic on it, like below,
iif(contains_key("data.pageUrl") && xdm.eventType.equals("web.webPageDetails.pageViews"), data.pageUrl, nullify())
//or
iif(contains_key("data.pageUrl") && xdm.eventType == "web.webPageDetails.pageViews", data.pageUrl, nullify())
This should fix the issue.
Cheers!
Thanks both for helping on this.
The iif function is working as expected, I was wrong.
The issue is coming from a different calculated field in the mapping of my datastream.
This one:
aa_get_product_names(data.products)
data.products is not always present and/or populated in the input json file, and apparently the function doesn't like it.
I removed this mapping from my datastream and all was ok but when I added it back, it went wrong again (others attributes are set to empty).
So now I'm trying to check if the attribute exists or not to call this function but it still wrong.
Here is the code I used to validate if the attribute is present:
iif(contains_key("data.products"), aa_get_product_names(data.products), nullify())
But I have to complete the condition because sometime, it's present but empty... could it cause issue ?
So I tested it like this but it's still not ok:
iif(contains_key("data.products") && (data.products!=""),aa_get_product_names(data.products), nullify())
Do you have any experience with the function aa_get_product_names?
I used this one because my input attribute looks like this:
"products": ";insurance"
Many thanks in advance
Robin
Hi @robinl39529461 ,
The aa_get_product_names function should work with the data you have given that the field is populated.
My first approach will be to work with developers and make sure that data.products is not sent if it doesn't have any value, so instead of sending it as an empty string or null simply remove it from the payload. and use this calculated field in your data prep,
iif(contains_key("data.products"), aa_get_product_names(data.products), nullify())
Incase the option to remove empty/null through development is not an option and you want to check it in data prep only then the calculated field you created should work if the data.products is sent as empty string but this logic will break if this field is sometimes also sent as null/undefined,
//empty field
"products": ""
//null field
"products":
In this case you'll have to account for those null values also and you can modify your logic as below,
iif(contains_key("data.products") && data.products!="" && data.products!=null, aa_get_product_names(data.products), nullify())
Regarding your point where you mentioned other fields are getting impacted by this transformation, that should not happen as a given transformation only applies to to target field that you are populating. Unless you are using that modified target field in some other transformations later in the data prep, those calculation will be getting to updated value and hence will be impacted.
Cheers!
Hi,
I tried this but it still doesn't work.
No idea of the reason but the function aa_get_product_names is causing side effect (call incomplete).
To test this, I removed if from the mapping datastream and all was back to normal.
So I tried also to manage the product mapping using context data, like this:
iif((contains_key("data.products") && data.formName!="" && data.products!="" && data.products!=null), data.products, nullify())
mapped to those target field:
=> productListItems[*].name
=> productListItems[*].SKU
but not working also. Maybe because I want to map a string to an array ???
The funny part is that if I test this way, it's ok:
iif((contains_key("data.products") && data.formName!="" && data.products!="" && data.products!=null), "Robin", "Sonika")
But I still don't get my real input data....
The solution was to adapt the structure of the json file to avoid to have to map it in datastream UI.
It's done like this and all is ok now:
"productListItems": [{
"name": "Pizza",
"SKU": "Pizza"
}],
Be careful that [ and ] are needed to be considered as an array and it works:
So no idea why was the explanation but at least I was able to make it works using a different way to send the data.
Thanks a lot for your help and all your propositions
Robin
@robinl39529461 wrote:
No idea of the reason but the function aa_get_product_names is causing side effect (call incomplete).
Hi team,
The AEP Error Response "Transformer internal error" and call incomplete occur because the function aa_get_product_names() requires a string, even if the iif() conditions are false.
So, my recommended solution is to use the concat() function to join data.products and an empty string. That way the required string for aa_get_product_names() will always be met whether or not the field is present. i.e.,:
iif(contains_key("data.products"), aa_get_product_names(concat(data.products,"")), nullify())
Views
Replies
Total Likes
@akrumins wrote:
iif(contains_key("data.products"), aa_get_product_names(concat(data.products,"")), nullify())
In fact, you may be able to do without the iff() operator and just use:
aa_get_product_names(concat(data.products,""))
What do we do with other functions like get_evars, get_price etc?
Do we still need to reference the concat and nullify ?
or just using the function is good enough
for example : aa_get_product_evars((data.__adobe.analytics.products), "eVar83")
Would this still be correct on pages where I dont see a product string set, it will throw a null , but that should be fine right ?
Views
Replies
Total Likes
@gauthammadala wrote:What do we do with other functions like get_evars, get_price etc?
Do we still need to reference the concat and nullify ?
In my testing, all of the aa_...() functions will break if there is no string available. So, you will have to use the concat() function to make sure a string is always present, even if the string is empty.
e.g.,
aa_get_product_evars(concat(data.__adobe.analytics.products,""), "eVar83")
Views
Replies
Total Likes
What do we do when we want to add fucntions for instance
coalesce(
aa_get_product_evars((data.__adobe.analytics.products), "eVar101"),
aa_get_product_evars((data.__adobe.analytics.products), "eVar70"),
aa_get_product_evars((data.__adobe.analytics.products), "eVar103"),
nullify())
The logic here is it should take the first non-null value.
How ever incase if I use your logic to add concat "" then it would show that as nonnull value right ?
Do you have any ideas/suggestions on how we can go about this ?
Views
Replies
Total Likes
@gauthammadala wrote:What do we do when we want to add fucntions for instance
coalesce(
aa_get_product_evars((data.__adobe.analytics.products), "eVar101"),
aa_get_product_evars((data.__adobe.analytics.products), "eVar70"),
aa_get_product_evars((data.__adobe.analytics.products), "eVar103"),
nullify())
Fortunately, we can preview how these functions will behave in Datastreams' "Create calculated field" UI.
Unfortunately, if your productString doesn't contain the specified eVar, the aa_get_product_evars() function will return an array containing null, which is technically not a null value. This means the coalesce() function will return the value "[null]" if the first product eVar is not present. We can see this is true if we use the to_array() function and despite setting the INCLUDE_NULLS parameter to false.
Depending on what you're trying to accomplish with the coalesce() function, you could combine it with the get_values() function. In the following example, the first available product eVar is returned:
SO, your script could use the following:
coalesce(
get_values(concat(data.__adobe.analytics.products,""), "eVar101","=","|"),
get_values(concat(data.__adobe.analytics.products,""), "eVar70","=","|"),
get_values(concat(data.__adobe.analytics.products,""), "eVar103","=","|"),
nullify()
)
Interesting I didnt know about get_values function, good to know.
I do use the calculated field UI to preview the fields.
However, the get_values is tricky if you have a string with multiple products for instance
";20023807;;;event1=1|event227=1;eVar8=1:2|eVar9=PLAN|eVar101=Secure ,;20023810;;;event1=1|event227=1;eVar8=2:2|eVar9=PLAN|eVar101=Smart"
As you can see here, I need both values [Secure,Smart] .
The aa_get_product_evars would give me this array
However the get_values can only give me Secure or Smart. Since when I reference "," as end of string I only get Secure but not Smart.
Views
Replies
Total Likes
@gauthammadala wrote:the get_values is tricky if you have a string with multiple products for instance
";20023807;;;event1=1|event227=1;eVar8=1:2|eVar9=PLAN|eVar101=Secure ,;20023810;;;event1=1|event227=1;eVar8=2:2|eVar9=PLAN|eVar101=Smart"
In the case of multi-product productStrings, the aa_get_product_evars function would suit best.
In my testing, however, the coalesce() function doesn't work with arrays despite the Data Prep Mapping Functions documentation saying the parameter requires an array.
Exactly,
Thats my issue here.
Because If I have multiple journeys and for Instance one journey could have eVar9 as my productname and another journey eVar11 could have my productname.
Now I would to get the values from either of these and map it to the same end point variable.
Believed Coalesce() function would do the job, not sure what would be the best approach for multi product. I am pretty sure someone or the other would have faced this before.
Views
Replies
Total Likes
What do we do with other functions like get_evars, get_price etc?
Do we still need to reference the concat and nullify ?
or just using the function is good enough
for example : aa_get_product_evars((data.__adobe.analytics.products), "eVar83")
Would this still be correct on pages where I dont see a product string set, it will throw a null , but that should be fine right ?
Views
Replies
Total Likes
@robinl39529461 Did you find the suggestions helpful? Please let us know if you need more information. If a response worked, kindly mark it as correct for posterity; alternatively, if you found a solution yourself, we’d appreciate it if you could share it with the community. Thank you!
Views
Replies
Total Likes
Views
Likes
Replies