Expand my Community achievements bar.

Nomination window for the Adobe Community Advisor Program, Class of 2025, is now open!

How to have a IF-THEN-ELSE condition in the UI mapping about datastream

Avatar

Level 3

Hi all, 
in this interface in AEPabout datastream mapping:

robinl39529461_0-1738687172714.png

 


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

5 Replies

Avatar

Level 3

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:

robinl39529461_0-1738689582995.png

So the condition is working when it's true but nothing about the false ....

Is the IIF different than the IF ?



Avatar

Adobe Champion

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?

Avatar

Level 7

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!