Search array in expression | Community
Skip to main content
January 12, 2023
Solved

Search array in expression

  • January 12, 2023
  • 2 replies
  • 1999 views

Hi,

I have a journey which triggers an event (first activity)

The parametrs in the event are - an array called "legs" and "customer Number" .

I am using a condition activity to check if a specific value within the array exists. 

Within the condition, I am passing the array and value as parameters using the "in" function.

Below is the expression:

If i check for the array at position 0, or at position 1, the expression looks correct with no error. However, if I want to search the whole array using "all()" the expression throws an error as below . How do I check if a value is present in all of the array?

 

Below is the schema structure:

 

Thanks in advance.

Ishani

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 akshaaga

Hi @ishanivshah ,

To check if a value is present in all elements of an array, you can use the "every" function in combination with the "in" function.

The "every" function takes a function as its argument, which is used to evaluate each element in the array. The "in" function returns a boolean value indicating whether a given value is in an array.

Here's an example of how you could modify your expression to check if a value is present in all elements of the "legs" array:

legs.every(function(leg) { return leg.value === "specific value"; });

This expression will return true if the "specific value" is present in every element of the "legs" array, and false otherwise. 

2 replies

Jyoti_Yadav
Level 8
February 7, 2023

Hi @ishanivshah ,

 

You can iterate throught the array using below syntax:

 

{{#each context.journey.profile.ArrayBetLegs.xxx as | legs |}}


{{ legs.name }} = {{ VALUE }}

{{/each}}

akshaaga
Adobe Employee
akshaagaAdobe EmployeeAccepted solution
Adobe Employee
February 11, 2023

Hi @ishanivshah ,

To check if a value is present in all elements of an array, you can use the "every" function in combination with the "in" function.

The "every" function takes a function as its argument, which is used to evaluate each element in the array. The "in" function returns a boolean value indicating whether a given value is in an array.

Here's an example of how you could modify your expression to check if a value is present in all elements of the "legs" array:

legs.every(function(leg) { return leg.value === "specific value"; });

This expression will return true if the "specific value" is present in every element of the "legs" array, and false otherwise. 

Level 3
July 6, 2023

Hi,

 

How can I use your function when my condition code looks like this:


containIgnoreCase(@{ord_paid._company.igOrder.igEntries.at(0).igArticleName.igArticleNameNL}, "geldterug")
or containIgnoreCase(@{ord_paid._company.igOrder.igEntries.at(0).igArticleName.igArticleNameNL}, "aanbetaling")

Thanks!