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:

                {
   "_experience":{
      "campaign":{
         "message":{
            "profile":{
               "pushNotificationTokens":[
                  {
                     "token":"token_1",
                     "application":{
                        "_id":"APP1",
                        "name":"MarltonMobileApp",
                        "version":"1.0"
                     }
                  },
                  {
                     "token":"token_2",
                     "application":{
                        "_id":"APP2",
                        "name":"MarketplaceApp",
                        "version":"1.0"
                     }
                  },
                  {
                     "token":"token_3",
                     "application":{
                        "_id":"APP3",
                        "name":"VendorApp",
                        "version":"2.0"
                     }
                  }
               ]
            }
         }
      }
   },
   "timestamp":"1536160728"
}

The function “all(<condition>)”

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

<listExpression>.all(<condition>)

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(@{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(@{LobbyBeacon._experience.campaign.message.profile.pushNotificationTokens.all().token}) > 0

The result will be true.

NOTE
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.
count(@{LobbyBeacon._experience.campaign.message.profile.pushNotificationTokens.token})

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.

count(#{ExperiencePlatform.MarltonExperience.experienceevent.all(
   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.

count(
 #{ExperiencePlatform.AnalyticsData.experienceevent.all(
 nowWithDelta(-7,"days") <= currentDataPackField.timestamp
 and currentDataPackField.application.firstLaunches.value > 0
)._id}) > 0
NOTE
currentEventField is only available when manipulating event collections and currentDataPackField
when manipulating data source collections. When processing collections with all, first and last, we
loop on each element of the collection one by one. currentEventField and currentDataPackField
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.

<listExpression>.first(<condition>)

<listExpression>.last(<condition>)

Example 1:

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

@{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.

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

The result is “token_2”.

NOTE
The experience events are retrieved from the 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.

#{ExperiencePlatform.AnalyticsProd_EvarsProps.experienceevent.first(
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.

<listExpression>.at(<index>)

Example:

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

@{LobbyBeacon._experience.campaign.message.profile.pushNotificationTokens.at(1).token}

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}
 #{ExperiencePlatform.ExperienceEventFieldGroup.experienceevent.last(
currentDataPackField.eventType == "commerce.productListAdds").productListItems.last(currentDataPackField.priceTotal >= 150).name}
recommendation-more-help
4f4a00c1-77c9-4eee-84df-bbe6206c3ab9