Collection management functions collection-management-functions

The expression language also introduces a set of functions to query collections.

These functions are explained below. In the following examples, let’s use the event payload containing a collection:


The function “all(<condition>)”

The all function enables the definition of a filter on a given collection by using a boolean expression.


For example, among all the app users, you can get the ones using IOS 13 (boolean expression “app used == IOS 13"). The result of this function is the filtered list containing items matching the boolean expression (example: app user 1, app user 34, app user 432).

In a Data Source Condition activity you can check if the result of the all function is null or not. You can also combine this all function with other functions such as count. For more information, see Data Source Condition activity.

Example 1:

We want to check if a user has installed a specific version of an application. For this we get all the push notification tokens associated with mobile applications for which the version is 1.0. Then, we perform a condition with the count function to check that the returned list of tokens contains at least one element.

count(@event{LobbyBeacon._experience.campaign.message.profile.pushNotificationTokens.all(currentEventField.application.version == "1.0").token}) > 0

The result is true.

Example 2:

Here we use the count function to check if there are push notification tokens in the collection.

count(@event{LobbyBeacon._experience.campaign.message.profile.pushNotificationTokens.all().token}) > 0

The result will be true.

When the filtering condition in the all() function is empty, the filter will return all the elements in the list. However, in order to count the number of elements of a collection, the all function is not required.

The result of the expression is 3.

Example 3:

Here we check if an individual has not received any communication within the last 24 hours. We filter the collection of experience events retrieved from the ExperiencePlatform datasource, using two expressions based on two elements of the collection. In particular, the timestamp of the event is compared to the dateTime returned by the nowWithDelta function.

   currentDataPackField.directMarketing.sends.value > 0 and
   currentDataPackField.timestamp > nowWithDelta(-1, "days")).timestamp}) == 0

The result will be true if there is no experience event matching the two conditions.

Example 4:

Here we want to check if an individual has launched at least once an application in the last 7 days, in order for instance to trigger a push notification inviting them to start a tutorial.

 nowWithDelta(-7,"days") <= currentDataPackField.timestamp
 and currentDataPackField.application.firstLaunches.value > 0
)._id}) > 0
currentEventField is only available when manipulating event collections, currentDataPackField when manipulating data source collections and currentActionField when manipulating custom action response collections.
When processing collections with all, first and last, we loop on each element of the collection one by one. currentEventField, currentDataPackField and currentActionField correspond to the element being looped.

The functions “first(<condition>)” and “last(<condition>)”

The first and last functions also enable the definition of a filter on the collection while returning the first/last element of the list that meets the filter.



Example 1:

This expression returns the first push notification token associated with mobile applications for which the version is 1.0.

@event{LobbyBeacon._experience.campaign.message.profile.pushNotificationTokens.first(currentEventField.application.version == "1.0").token

The result is “token_1”.

Example 2:

This expression returns the last push notification token associated with mobile applications for which the version is 1.0.

@event{LobbyBeacon._experience.campaign.message.profile.pushNotificationTokens.last(currentEventField.application.version == "1.0").token}

The result is “token_2”.

The experience events are retrieved from Adobe Experience Platform as a collection in reverse chronological order, hence :
  • first function will return the most recent event
  • last function will return the oldest one.

Example 3:

We check whether the first (most recent) Adobe Analytics event with a non-zero value for DMA ID has a value equal to 602.

currentDataPackField.placeContext.geo.dmaID > 0).placeContext.geo.dmaID} == 602

The function “at(<index>)”

The at function allows you to reference a specific element in a collection according to an index.
Index 0 is the first index of the collection.



This expression returns the second push notification token of the list.


The result is “token_2”.

Other examples

#{ExperiencePlatform.ExperienceEventFieldGroup.experienceevent. all(currentDataPackField._aepgdcdevenablement2.purchase_event.receipt_nbr == "10-337-4016").
_aepgdcdevenablement2.purchase_event.productListItems. all(currentDataPackField.SKU == "AB17 1234 1775 19DT B4DR 8HDK 762").name}
currentDataPackField.eventType == "commerce.productListAdds").productListItems.last(currentDataPackField.priceTotal >= 150).name}