Expand my Community achievements bar.

Dive in, experiment, and see how our AI Assistant Content Accelerator can transform your workflows with personalized, efficient content solutions through our newly designed playground experience.
SOLVED

How does the contain function work?

Avatar

Level 3

Hi,

 

I want to check if the word 'POST' comes back in a contextual attribute: {{context.journey.events.00000._company.igOrder.igEntries.CarrierUid}}

 

So I want this:

 

If {{context.journey.events.00000._company.igOrder.igEntries.CarrierUid}} contains the word 'Post' ( not case sensitive), I want to show: "Post bezorging" in the e-mail.

 

I know how to use the if statements, but the documentation is totally not clear about how to use the contain function. 

 

Can someone help me with this?

 

Thanks!!

1 Accepted Solution

Avatar

Correct answer by
Level 3

Hi,

 

Thanks for all your help!

It turned out that the field was an array, so I have to use the each function first. Did that and then it worked  

 

@_Manoj_Kumar_ 

View solution in original post

9 Replies

Avatar

Community Advisor

Hello @Taal 

 

You can do it like this.

 

{%#if(contains(context.journey.events.00000._company.igOrder.igEntries.CarrierUid, "post", false)) %}
If field containss post print something
{% else %}
Post not found in the field
{%/if%}

 

More info on function is available here: String functions library | Adobe Journey Optimizer

 


     Manoj
     Find me on LinkedIn

Avatar

Level 3

Hi, I tried these two ways, but they don't work. Do you know how else I could try it? Thanks for your help! @_Manoj_Kumar_ Schermafbeelding 2023-03-22 103943.pngSchermafbeelding 2023-03-22 103838.png

Avatar

Community Advisor

@Taal remove the single quote around the event id

content.journey.event.'816428911'


     Manoj
     Find me on LinkedIn

Avatar

Community Advisor

Just tested it. That won't work either.

 

It seems all these functions are designed to work independently. If we wrap them within other functions they are not working. 


     Manoj
     Find me on LinkedIn

Avatar

Level 5

Maybe try this? single quotes and little change in format.

if contains({{context.journey.events.00000._company.igOrder.igEntries.CarrierUid}}, 'Post') {
  // email
}

 

Avatar

Correct answer by
Level 3

Hi,

 

Thanks for all your help!

It turned out that the field was an array, so I have to use the each function first. Did that and then it worked  

 

@_Manoj_Kumar_ 

Avatar

Community Advisor

Hello @Taal, If possible, could you please share the code?

 

It does not work for me.

Manoj_Kumar__0-1680137190049.png

 


     Manoj
     Find me on LinkedIn

Avatar

Level 3

Sure! 

 

Note that the field that I use is an array, so if your field is not an array, you should not use the 'each' part:

 

{{#each context.journey.events.xxxxxx._company.igOrder.igEntries as |entry|}}

{%#if contains(entry.CarrierUid, "post", false) %}PostNL{%else if contains(entry.CarrierUid, "zzz", false)%}zzz{%else%} 
External {%/if%}


{{/each}}