列表函数 list-functions
列表函数允许您处理和处理历程表达式中的值集合。 这些功能对于过滤、排序、转换和分析客户历程中的阵列和列表至关重要。
当您需要执行以下操作时,请使用列表函数:
- 根据条件(筛选器,getListItem)从收藏集中筛选和提取特定项
- 按升序或降序对列表元素进行排序和组织(排序)
- 删除重复项,并从列表(distinct, distinctWithNull)中获取唯一值
- 检查集合(in)中是否存在值
- 限制从列表返回的项目数(limit)
- 获取列表的大小(listSize)或将列表转换为不同的格式(serializeList)
- 执行集合操作,如查找列表(相交)之间的公共元素、组合列表(mergeLists)或从另一个列表中减去一个列表(differenceLists)
列表函数提供了用于处理复杂数据结构的强大工具,支持基于收集内容的复杂数据操作和条件逻辑。
差异列表 differenceLists
返回第一个列表中不存在于第二个列表中的项(设置差异: list 1 - list 2)。 将跳过Null条目。 结果将始终删除重复值并保留第一个列表的插入顺序。
differenceLists(<parameters>)| table 0-row-3 1-row-3 2-row-3 | ||
|---|---|---|
| 参数 | 类型 | 描述 |
| 列表1 | listString、listInteger、listDecimal、listBoolean、listDuration、listDateTime、listDateTimeOnly或listDateOnly | 要从中减去的列表。 |
| 列表2 | 与列表1的类型相同。 | 要从列表1中移除的项的列表。 |
differenceLists(listString,listString):列表字符串
differenceLists(listInteger,listInteger): listInteger
differenceLists(listDecimal,listDecimal): listDecimal
differenceLists(listBoolean,listBoolean):列表布尔值
differenceLists(listDuration,listDuration): listDuration
differenceLists(listDateTime,listDateTime): listDateTime
differenceLists(listDateTimeOnly,listDateTimeOnly): listDateTimeOnly
differenceLists(listDateOnly,listDateOnly): listDateOnly
| code language-json |
|---|
|
返回['a','c']。
| code language-json |
|---|
|
返回['a','b']。
| code language-json |
|---|
|
返回[]。
distinct distinct
返回给定列表的不同值或对象。 Null条目将被忽略。
distinct(<parameters>)| table 0-row-3 1-row-3 2-row-3 | ||
|---|---|---|
| 参数 | 类型 | 描述 |
| listToProcess | listString、listBoolean、listInteger、listDecimal、listDuration、listDateTime、listDateTimeOnly、listDateOnly或listObject | 要处理的列表。 对于listObject,它必须是字段引用。 |
| keyAttributeName | 字符串 | 此参数是可选的,并且仅适用于listObject。 如果未提供参数,则当所有属性都具有相同的值时,会将对象视为重复。 否则,如果给定的属性具有相同的值,则将对象视为重复。 |
distinct(<listInteger>)
返回整数列表。
distinct(<listDecimal>)
返回小数位数列表。
distinct(<listString>)
返回字符串列表。
distinct(<listDateTimeOnly>)
返回不考虑时区的日期时间列表。
distinct(<listDateTime>)
返回日期时间列表。
distinct(<listDateOnly>)
返回日期列表。
distinct(<listBoolean>)
返回布尔值列表。
distinct(<listDuration>)
返回持续时间列表。
distinct(<listObject>)
distinct(<listObject>,<string>)
返回对象列表。
distinct([10,2,10,null])
返回[10, 2]。
distinctWithNull distinctWithNull
返回给定列表的不同值或对象。 如果列表至少有一个null条目,则返回的列表中将显示一个null条目。
distinctWithNull(<parameters>)| table 0-row-3 1-row-3 | ||
|---|---|---|
| 参数 | 类型 | 描述 |
| listToProcess | listString、listBoolean、listInteger、listDecimal、listDuration、listDateTime、listDateTimeOnly、listDateOnly | 要处理的列表。 |
distinctWithNull(<listInteger>)
返回整数列表。
distinctWithNull(<listDecimal>)
返回小数位数列表。
distinctWithNull(<listString>)
返回字符串列表。
distinctWithNull(<listDateTimeOnly>)
返回不考虑时区的日期时间列表。
distinctWithNull(<listDateTime>)
返回日期时间列表。
distinctWithNull(<listDateOnly>)
返回日期列表。
distinctWithNull(<listBoolean>)
返回布尔值列表。
distinctWithNull(<listDuration>)
返回持续时间列表。
distinctWithNull([10,2,10,null])
返回[10, 2, null]
注意:此函数不支持参数<listObject>。
filter filter
返回一个listObject,其中的对象具有匹配给定键值之一的键属性。
filter(<parameters>)| table 0-row-3 1-row-3 2-row-3 3-row-3 | ||
|---|---|---|
| 参数 | 类型 | 描述 |
| listToFilter | listObject | 要过滤的对象列表。 它必须是字段引用。 |
| keyAttributeName | 字符串 | 给定列表对象中的属性名称,用作筛选键 |
| keyValueList | list | 用于过滤的键值数组 |
filter(listObject, string, listString)
filter(listObject, string, listInteger)
filter(listObject, string, listDecimal)
filter(listObject, string, listDateTime)
filter(listObject, string, listDateTimeOnly)
filter(listObject, string, listDateOnly)
filter(listObject, string, listDuration)
filter(listObject, string, listBoolean)
返回listObject。
以下是在传入事件“myevent”中传递的有效负载示例:
| code language-json |
|---|
|
您可以使用以下表达式:
| code language-json |
|---|
|
返回包含两个对象的listObject,其中“product2”和“product3”作为ID。
getListItem getListItem
返回给定索引处的列表项。
getListItem(<parameters>)| table 0-row-2 1-row-2 2-row-2 3-row-2 4-row-2 5-row-2 6-row-2 7-row-2 8-row-2 9-row-2 | |
|---|---|
| 参数 | 类型 |
| list | listString |
| list | listBoolean |
| list | listInteger |
| list | listDecimal |
| list | listDuration |
| list | listDateTime |
| list | listDateTimeOnly |
| list | listDateOnly |
| index | 整数 |
getListItem(<listInteger>,<index>)
返回整数。
getListItem(<listDecimal>,<index>)
返回小数。
getListItem(<listString>,<index>)
返回字符串。
getListItem(<listDateTimeOnly>,<index>)
返回不考虑时区的日期时间。
getListItem(<listDateTime>,<index>)
返回日期时间。
getListItem(<listDateOnly>,<index>)
返回日期列表。
getListItem(<listBoolean>,<index>)
返回布尔值。
getListItem(<listDuration>,<index>)
返回持续时间。
getListItem([10, 2, 3], 1)
返回“2”
getListItem(["A", "B", "C"], 2)
返回“C”
具有事件字段"event.appVersion"且值为"20.45.2.3434"的示例
split(@event{event.appVersion}, "\\.")
返回["20", "45", "2", "3434"]
getListItem(split(@event{event.appVersion}, "\\."), 0)
返回“20”
in in
检查第一个参数值是否在列表中。 检查通过对每个参数值执行Equal。 如果找到参数值,则返回true;否则,返回false。
<expression>的类型必须与列表项匹配。 作为提醒,列表的项目类型必须匹配。
in(<parameters>)| table 0-row-2 1-row-2 2-row-2 3-row-2 4-row-2 5-row-2 6-row-2 7-row-2 8-row-2 9-row-2 10-row-2 11-row-2 12-row-2 13-row-2 14-row-2 15-row-2 | |
|---|---|
| 参数 | 类型 |
| 字符串 | 字符串 |
| 布尔值 | 布尔值 |
| 整数 | 整数 |
| 小数 | 小数 |
| 持续时间 | 持续时间 |
| 日期时间 | 日期时间 |
| DateTimeOnly | DateTimeOnly |
| 列表 | listString |
| 列表 | listBoolean |
| 列表 | listInteger |
| 列表 | listDecimal |
| 列表 | listDuration |
| 列表 | listDateTime |
| 列表 | listDateTimeOnly |
| 列表 | listDateOnly |
in(<integer>,<listInteger>)
in(<decimal>,<listDecimal>)
in(<string>,<listString>)
in(<boolean>,<listBoolean>)
in(<dateTimeOnly>,<listDateTimeOnly>)
in(<dateTime>,<listDateTime>)
in(<dateOnly>,<listDateOnly>)
in(<duration>,<listDuration>)
返回布尔值。
in(4,[4,5,3,4])
返回真。
in(8,[4,5,3,4])
返回假。
in(#{ExperiencePlatform.ProfileFieldGroup.profile.person.gender}, ["male"])
intersect intersect
返回两个输入列表中的公用值。 如果两个列表之一为null,则返回空列表。
intersect(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 参数 | 类型 |
| 列表1 | list |
| 列表2 | list |
intersect(listString,listString):列表字符串
intersect(listDecimal,listDecimal): listDecimal
intersect(listInteger,listInteger): listInteger
intersect(listDateTime,listDateTime): listDateTime
intersect(listDateTimeOnly,listDateTimeOnly): listDateTimeOnly
intersect(listDateOnly,listDateOnly): listDateOnly
intersect(listDuration,listDuration): listDuration
intersect(listBoolean,listBoolean):列表布尔值
返回列表。
| code language-json |
|---|
|
返回[“sports”,“news”]
| code language-json |
|---|
|
返回配置文件属性和给定类别列表之间的通用项目。
| code language-json |
|---|
|
返回用户档案属性和给定事件字段之间的公用项。
limit limit
返回列表的第一个或最后的N个元素。
limit(<parameters>)| table 0-row-3 1-row-3 2-row-3 3-row-3 | ||
|---|---|---|
| 参数 | 类型 | 描述 |
| listToProcess | listString、listBoolean、listInteger、listDecimal、listDuration、listDateTime、listDateTimeOnly、listDateOnly或listObject | 要考虑的列表。 对于listObject,它必须是字段引用。 |
| 项目数 | 整数 | 要从给定列表中返回的项目数。 |
| firstOrLastItems | 布尔 | 此参数是可选的(默认为true)。 true返回第一项。 false返回最后一个项目。 |
limit(<listString>,<integer>)
limit(<listString>,<integer>,<boolean>)
返回字符串列表。
limit(<listInteger>,<integer>)
limit(<listInteger>,<integer>,<boolean>)
返回整数列表。
limit(<listDecimal>,<integer>)
limit(<listDecimal>,<integer>,<boolean>)
返回小数位数列表。
limit(<listBoolean>,<integer>)
limit(<listBoolean>,<integer>,<boolean>)
返回布尔值列表。
limit(<listDateOnly>,<integer>)
limit(<listDateOnly>,<integer>,<boolean>)
返回日期列表。
limit(<listDateTimeOnly>,<integer>)
limit(<listDateTimeOnly>,<integer>,<boolean>)
返回不考虑时区的日期时间列表。
limit(<listDateTime>,integer>)
limit(<listDateTime>,<integer>,<boolean>)
返回日期时间列表。
limit(<listDuration>,<integer>)
limit(<listDuration>,<integer>,<boolean>)
返回持续时间列表。
limit(<listObject>,<integer>)
limit(<listObject>,<integer>,<boolean>)
返回对象列表。
limit(["A", "B", "C", "D", "E"], 3)
返回["A","B","C"]。
limit(["A", "B", "C", "D", "E"], 3, false)
返回["C","D","E"]。
listSize listSize
计算列表中的元素数。
listSize(<parameters>)| table 0-row-3 1-row-3 | ||
|---|---|---|
| 参数 | 类型 | 描述 |
| listToProcess | listString、listBoolean、listInteger、listDecimal、listDuration、listDateTime、listDateTimeOnly、listDateOnly或listObject | 要处理的列表。 对于listObject,它必须是字段引用。 listObject不能包含null对象。 |
listSize(<listInteger>)
listSize(<listDecimal>)
listSize(<listString>)
listSize(<listBoolean>)
listSize(<listDateTimeOnly>)
listSize(<listDateTime>)
listSize(<listDateOnly>)
listSize(<listDuration>)
返回整数。
listSize(<listObject>)
listSize([10,2,3])
返回3。
listSize(@event{my_event.productListItems})
返回给定对象数组(listObject类型)中的对象数。
mergeList mergeLists
组合两个列表。 当deduplicate为true时,返回已删除重复值的两个列表的并集。 当deduplicate为false时,返回两个列表(列表1的项目后跟列表2的项目)的拼合,保留重复项。 将跳过Null条目。
注意: deduplicate参数必须是文字true或false,而不是动态布尔表达式。
mergeLists(<parameters>)| table 0-row-3 1-row-3 2-row-3 3-row-3 | ||
|---|---|---|
| 参数 | 类型 | 描述 |
| 列表1 | listString、listInteger、listDecimal、listBoolean、listDuration、listDateTime、listDateTimeOnly或listDateOnly | 第一个列表。 它的项目首先添加到结果中。 |
| 列表2 | 与列表1的类型相同。 | 第二个列表。 其项添加到列表1的项目之后。 |
| 删除重复项 | 布尔型 | true返回已删除重复项的两个列表的并集。 false返回两个列表的连接,保留重复项。 必须为文本true或false。 |
mergeLists(listString,listString,boolean):列表字符串
mergeLists(listInteger,listInteger,boolean): listInteger
mergeLists(listDecimal,listDecimal,boolean): listDecimal
mergeLists(listBoolean,listBoolean,boolean):列表布尔值
mergeLists(listDuration,listDuration,boolean): listDuration
mergeLists(listDateTime,listDateTime,boolean): listDateTime
mergeLists(listDateTimeOnly,listDateTimeOnly,boolean): listDateTimeOnly
mergeLists(listDateOnly,listDateOnly,boolean): listDateOnly
| code language-json |
|---|
|
返回['a','b','c']。
| code language-json |
|---|
|
返回['a','b','b','c']。
serializeList serializeList
将给定列表(除listObject之外的任何类型)转换为字符串。
serializeList(<parameters>)| table 0-row-3 1-row-3 2-row-3 3-row-3 | ||
|---|---|---|
| 参数 | 类型 | 描述 |
| listToProcess | listString、listBoolean、listInteger、listDecimal、listDuration、listDateTime、listDateTimeOnly、listDateOnly | 要转换为字符串的列表。 |
| 分隔符 | 字符串 | 输出字符串中每个列表元素之间的分隔符。 |
| addQuotes | 布尔 | 此参数指示输出字符串中的每个元素是否应包含引号(true)或(false)。 |
serializeList(<listInteger>,<string>,<boolean>)
serializeList(<listDecimal>,<string>,<boolean>)
serializeList(<listString>,<string>,<boolean>)
serializeList(<listBoolean>,<string>,<boolean>)
serializeList(<listDateTimeOnly>,<string>,<boolean>)
serializeList(<listDateTime>,<string>,<boolean>)
serializeList(<listDateOnly>,<string>,<boolean>)
serializeList(<listDuration>,<string>,<boolean>)
返回字符串。
serializeList(["Hello","World"], " ", false)
返回“Hello World”。
serializeList(["Hello", "World"], ",", true)
返回“Hello”、“World”。
sort sort
以自然顺序对值列表或对象进行排序。
sort(<parameters>)| table 0-row-3 1-row-3 2-row-3 3-row-3 | ||
|---|---|---|
| 参数 | 类型 | 描述 |
| listToSort | listString、listBoolean、listInteger、listDecimal、listDuration、listDateTime、listDateTimeOnly、listDateOnly或listObject | 要排序的列表。 对于listObject,它必须是字段引用。 |
| keyAttributeName | 字符串 | 此参数仅适用于listObject。 给定列表中的对象中的属性名称用作排序的键。 |
| sortingOrder | 布尔 | 升序(true)或降序(false) |
sort(<listInteger>,<boolean>)
返回整数列表。
sort(<listDecimal>,<boolean>)
返回小数位数列表。
sort(<listString>,<boolean>)
返回字符串列表。
sort(<listDateTimeOnly>,<boolean>)
返回不考虑时区的日期时间列表。
sort(<listDateTime>,<boolean>)
返回日期时间列表。
sort(<listDateOnly>,<boolean>)
返回日期列表。
sort(<listBoolean>,<boolean>)
返回布尔值列表。
sort(<listObject>,<string>,<boolean>)
返回对象列表。
sort(["A", "C", "B"], true)
返回["A","B","C"]。
sort([1, 3, 2], false)
返回[3, 2, 1]。
sort(@event{my_event.productListItems}, "SKU", true)
返回按SKU属性排序的listObject(升序)
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 all list functions available in AJO journey expressions, covering how to filter, sort, deduplicate, check membership, limit, serialize, merge, subtract, and find intersections of lists and arrays.
Intents:
- Remove duplicate values from a list using
distinct(ignoring nulls) ordistinctWithNull(preserving nulls) - Filter a listObject to return only objects matching specific key values using
filter - Retrieve an element at a specific index from a list using
getListItem - Check whether a value exists in a list using
in - Find common elements between two lists using
intersect - Combine two lists, with or without deduplication, using
mergeLists - Subtract one list from another (set difference) using
differenceLists - Return the first or last N elements of a list using
limit - Count the total number of elements in a list using
listSize - Convert a list to a delimited string using
serializeList - Sort a list in ascending or descending order using
sort
Glossary:
- listObject: A list of complex objects that must be a field reference; cannot contain null objects (product-specific)
- keyAttributeName: An optional string parameter used with
distinct,filter, andsortto identify which object attribute to use for deduplication, filtering, or sorting (product-specific) - intersect: A set operation returning only the elements present in both input lists
- mergeLists: A set operation returning the union (deduplicated) or concatenation (with duplicates) of two lists, depending on the
deduplicateparameter (product-specific) - differenceLists: A set operation returning the items of the first list that are not present in the second list (product-specific)
Guardrails:
distinctWithNulldoes not support the<listObject>parameter typefilterrequires the listObject parameter to be a field reference, not an inline literallistSizeon a listObject requires the list to be a field reference; a listObject cannot contain null objectsserializeListdoes not support thelistObjecttypemergeListsanddifferenceListsonly support scalar list types (string, integer, decimal, boolean, dateTime, dateTimeOnly, dateOnly, duration);listObjectis not supportedmergeLists’sdeduplicateparameter must be a literaltrue/false, not a dynamic boolean expressiondifferenceListsalways deduplicates its result; there is no option to keep duplicates
Terminology:
- Canonical name: List functions — Acronym: none — variants: collection functions, array functions
- Synonyms: “listSize” = “count list elements”; “serializeList” = “join list to string”
- Do not confuse: “distinct” (ignores nulls) ≠ “distinctWithNull” (preserves null as a distinct value)
- Do not confuse: “limit” with third parameter
true(returns first N items) ≠ “limit” withfalse(returns last N items) - Do not confuse: “intersect” (common elements between two lists) ≠ “filter” (elements matching specific key values)
- Do not confuse: “mergeLists” (combines two lists, union or concatenation) ≠ “differenceLists” (subtracts one list from another) ≠ “intersect” (common elements only)
FAQ:
- Q: How do I get the first 3 items of a list? — Use
limit(myList, 3)orlimit(myList, 3, true); the default is to return the first items. - Q: How do I get the last 3 items of a list? — Use
limit(myList, 3, false). - Q: What is the difference between
distinctanddistinctWithNull? —distinctignores null values and excludes them from the result;distinctWithNulltreats null as a distinct value and includes one null entry if any nulls are present. - Q: Can I filter a list of strings with
filter? — No,filteronly works onlistObject; for scalar lists useinordistinctfor deduplication. - Q: How do I check if a value is in a list? — Use
in(value, myList), which returns true if the value is found in the list. - Q: Can I sort a listObject by a specific attribute? — Yes, use
sort(@event{...}, "attributeName", true)where the second parameter is the attribute name and the third is the sort direction (true = ascending). - Q: How do I combine two lists and remove duplicates? — Use
mergeLists(list1, list2, true). - Q: How do I combine two lists but keep duplicate values? — Use
mergeLists(list1, list2, false). - Q: How do I find the items in one list that are not in another? — Use
differenceLists(list1, list2), which returns the items oflist1not present inlist2. - Q: What is the difference between
intersectanddifferenceLists? —intersectreturns items common to both lists;differenceListsreturns items in the first list that are absent from the second list.