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

Search array in expression

Avatar

Level 1

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:

IshaniVShah_2-1673504454217.png

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?

 

IshaniVShah_1-1673504424362.png

Below is the schema structure:

IshaniVShah_3-1673504505459.png

 

Thanks in advance.

Ishani

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

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. 

View solution in original post

3 Replies

Avatar

Community Advisor

Hi @IshaniVShah ,

 

You can iterate throught the array using below syntax:

 

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


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

{{/each}}

Avatar

Correct answer by
Employee Advisor

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. 

Avatar

Level 3

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!