コレクション管理関数 collection-management-functions

クエリコレクション関数について

式言語には、クエリコレクションに対する一連の関数も導入されています。 これらの関数について以下で説明します。

次の例では、プッシュ通知トークンのコレクションを含む「LobbyBeacon」という名前のイベントを使用します。 このページの例では、以下に示すイベントペイロード構造を使用しています。

                {
   "_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"
}
NOTE
以下の例では、このペイロードは @event{LobbyBeacon._experience.campaign.message.profile.pushNotificationTokens} を使用して参照されています。ここで、「LobbyBeacon」はイベント名で、残りのパスは上記の構造に対応しています。

all(<condition>) 関数

この all 関数では、ブール式を使用して指定のコレクションに対するフィルターを定義できます。

<listExpression>.all(<condition>)

概念的な例:​すべてのアプリユーザーの中から、iOS 13 を使用しているユーザーを取得できます(ブール式「app used == IOS 13」)。 この関数の結果は、ブール式に一致する項目(例:アプリユーザー 1、アプリユーザー 34、アプリユーザー 432)を含んだフィルター済みリストになります。

「データソースの条件」アクティビティでは、all 関数の結果が null かどうかを確認できます。 また、この all 関数を、count 関数などの他の関数と組み合わせることができます。 詳しくは、「データソースの条件」アクティビティを参照してください。

LobbyBeacon ペイロードを使用したコード例:

以下の例では、このページの上部に表示されるイベントペイロードを使用しています。

CAUTION
ジャーニーの式/条件でのエクスペリエンスイベントの使用はサポートされていません。 ユースケースでエクスペリエンスイベントを使用する必要がある場合は、別の方法を考慮します。 詳細情報

例 1

ユーザーが特定のバージョンのアプリケーションをインストールしてあるかどうかを確認します。 このために、バージョンが1.0のモバイルアプリケーションに関連付けられたすべてのプッシュ通知トークンを取得します。 次に、count​関数を使用して条件を実行し、返されるトークンのリストに少なくとも1つの要素が含まれていることを確認します。

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

結果は true です。

例 2

ここでは、count 関数を使用して、コレクションにプッシュ通知トークンがあるかどうかを確認します。

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

結果は true です。

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

式の結果は 3 です。

NOTE
  • all() 関数のフィルター条件に何も指定していない場合、フィルターはリスト内のすべての要素を返します。 ただし、コレクションの要素数をカウントするためには、all 関数は不要です。

  • currentEventField はイベントコレクションを操作する場合、currentDataPackField はデータソースコレクションを操作する場合、currentActionField はカスタムアクションの応答コレクションを操作する場合にのみ使用できます。

allfirstlast でコレクションを処理する場合、コレクションの各要素を 1 つずつループします。 currentEventFieldcurrentDataPackFieldcurrentActionField は、ループする要素に対応します。

first(<condition>) 関数と last(<condition>) 関数

first 関数と last 関数では、コレクションのフィルターを定義できる一方、フィルター条件を満たすリストの最初または最後の要素を返すこともできます。

<listExpression>.first(<condition>)

<listExpression>.last(<condition>)

例 1

この式は、バージョンが 1.0 のモバイルアプリケーションに関連付けられた最初のプッシュ通知トークンを返します。

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

結果は token_1 です。

例 2

この式は、バージョンが 1.0 のモバイルアプリケーションに関連付けられた最後のプッシュ通知トークンを返します。

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

結果は token_2 です。

at(<index>) 関数

at 関数を使用すると、インデックスに従ってコレクション内の特定の要素を参照できます。
インデックス 0 はコレクションの最初のインデックスです。

<listExpression>.at(<index>)

この式は、リストの 2 番目のプッシュ通知トークンを返します。

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

結果は token_2 です。

AI Knowledge Reference

This section contains structured knowledge intended to support interpretation, retrieval, and question answering related to this topic.

For complete understanding, this information should be combined with the documentation on this page. Neither source is intended to stand alone; the page describes the feature, while this section provides additional context that helps disambiguate terminology, intent, applicability, and constraints.

  • TL;DR: This page documents the all(), first(), last(), and at() collection management functions used in the Journey advanced expression editor, illustrated with push notification token payload examples.

Intents:

  • Filter a collection of event or data source fields using a boolean condition with all(<condition>)
  • Count filtered or unfiltered collection elements using count() combined with collection functions
  • Retrieve the first or last matching element of a collection using first() or last()
  • Access a collection element at a specific zero-based index using at(<index>)
  • Understand which loop variable (currentEventField, currentDataPackField, currentActionField) applies to each collection context

Glossary:

  • all(condition): Filters a collection and returns all items matching the given boolean expression (product-specific)
  • first(condition): Returns the first (most recent for experience events) element in a collection matching the condition (product-specific)
  • last(condition): Returns the last (oldest for experience events) element in a collection matching the condition (product-specific)
  • at(index): Returns the element at the specified zero-based index of a collection (product-specific)
  • currentEventField: Loop variable available only when iterating over event collections (product-specific)
  • currentDataPackField: Loop variable available only when iterating over data source collections (product-specific)
  • currentActionField: Loop variable available only when iterating over custom action response collections (product-specific)

Guardrails:

  • Using experience events in journey expressions/conditions is not supported; consider alternative methods such as computed attributes
  • currentEventField, currentDataPackField, and currentActionField are only available inside their respective collection contexts
  • The all function is not required to count collection elements — count() can be applied directly to the field path
  • When all() is called with an empty condition, all elements in the collection are returned

Terminology:

  • Canonical name: Collection Management Functions — Acronym: none — variants: collection functions, query collection functions
  • Synonyms: “all()” = “collection filter function”; “at()” = “index accessor”
  • Do not confuse: first() (most recent experience event) ≠ first inserted element in general lists

FAQ:

  • Q: What is the difference between all() with an empty condition and all() with a condition? — An empty all() returns every element; a condition-based all() returns only elements matching that boolean expression.
  • Q: How do I count push notification tokens without using all()? — Call count() directly on the token field path, e.g. count(@event{LobbyBeacon...pushNotificationTokens.token}).
  • Q: Which variable do I use to reference the current element when looping over a data source collection? — Use currentDataPackField inside all(), first(), or last() on data source collections.
  • Q: How do I get the second item in a collection? — Use at(1) because index 0 is the first element.
  • Q: Why does last() return the oldest experience event? — Experience events are stored in reverse chronological order, so the last position in the collection corresponds to the oldest event.
recommendation-more-help
journey-optimizer-help