How to determine which field to show from an array | Community
Skip to main content
Level 3
July 15, 2024
Solved

How to determine which field to show from an array

  • July 15, 2024
  • 1 reply
  • 888 views

Hi,

 

We want to show the loyalty card number in e-mails to our customers. You can have multiple loyalty card numbers, so it is an array.

We want to show the loyalty card number that starts with 2616. How can I do that? 

 

{{profile._company.LoyaltyCards.LoyaltyCardNumber}} 

 

If I make an each and then add the field, it will show every loyalty card number, but I only want to show the one that starts with 2616.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Mohan_Dugganab

You can try this


{% let idx = 0 %}
{{#each profile._company.LoyaltyCards as |p|}}
{%#if startsWith(p,"2616") and idx < 1 %}

{{p}}
{% let idx = idx + 1%}
{%/if%}{{/each}}



1 reply

Mohan_Dugganab
Adobe Employee
Adobe Employee
July 15, 2024

You can have a helper on the following lines - 

 

{{#each profile._company.LoyaltyCards.LoyaltyCardNumber as |p|}}

{%#if startsWith(p,"2616") %}

{{p}}

{%/if%}

{{/each}}

 

https://experienceleague.adobe.com/en/docs/journey-optimizer/using/content-management/personalization/functions/string#startswith

https://experienceleague.adobe.com/en/docs/journey-optimizer/using/content-management/personalization/functions/helpers

 

TalithaPaAuthor
Level 3
July 15, 2024

Hi, 

 

I tried this: 

{{#each profile._company.LoyaltyCards as|entry|}}

{%#if startsWith(entry.LoyaltyCardNumber,"2616")%} {{entry.LoyaltyCardNumber}}

 

{%else if doesNotStartWith(entry.LoyaltyCardNumber, "2616")%}
else {{entry.LoyaltyCardNumber}}

{%/if%} {{/each}}

The weird thing is, that it gives back this: 

2616069166373 else 2616069171476 2616069173081 2616069171506

While I defined condition 2 as doesNotStartWith. 

The profile can have multiple loyalty card numbers and in this case also multiple loyalty card numbers that start with 2616

Mohan_Dugganab
Adobe Employee
Mohan_DugganabAdobe EmployeeAccepted solution
Adobe Employee
July 15, 2024

You can try this


{% let idx = 0 %}
{{#each profile._company.LoyaltyCards as |p|}}
{%#if startsWith(p,"2616") and idx < 1 %}

{{p}}
{% let idx = idx + 1%}
{%/if%}{{/each}}