Expand my Community achievements bar.

The 2nd edition of the Journey Optimizer Community Lens newsletter is out now!
SOLVED

How does the contain function work?

Avatar

Level 2

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 2

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_ 

1 Reply

Avatar

Community Advisor

Hello @icostan2 

 

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

 

Avatar

Level 2

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

@icostan2 remove the single quote around the event id

content.journey.event.'816428911'

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. 

Avatar

Level 4

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 2

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 @icostan2, If possible, could you please share the code?

 

It does not work for me.

Manoj_Kumar__0-1680137190049.png

 

Avatar

Level 2

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}}