Funzioni elenco list-functions

Le funzioni elenco consentono di manipolare e utilizzare insiemi di valori all’interno delle espressioni di percorso. Queste funzioni sono essenziali per filtrare, ordinare, trasformare e analizzare array ed elenchi nei percorsi dei clienti.

Utilizza le funzioni elenco quando devi:

  • Filtra ed estrai elementi specifici dalle raccolte in base ai criteri (filter, getListItem)
  • Ordina e organizza gli elementi elenco in ordine crescente o decrescente (ordina)
  • Rimuovi i duplicati e ottieni valori univoci dagli elenchi (distinct, distinctWithNull)
  • Verifica se i valori esistono nelle raccolte (in)
  • Limita il numero di elementi restituiti da un elenco (limit)
  • Ottenere le dimensioni di un elenco (listSize) o trasformare gli elenchi in formati diversi (serializeList)
  • Eseguire operazioni sui set, ad esempio la ricerca di elementi comuni tra elenchi (intersect), la combinazione di elenchi (mergeLists) o la sottrazione di un elenco da un altro (differenceLists)

Le funzioni elenco forniscono potenti strumenti per l’utilizzo di strutture di dati complesse, consentendo una sofisticata manipolazione dei dati e una logica condizionale basata sui contenuti della raccolta.

differenceLists differenceLists

Restituisce gli elementi del primo elenco non presenti nel secondo elenco (differenza impostata: list 1 - list 2). Le voci nulle vengono ignorate. Il risultato rimuove sempre i valori duplicati e mantiene l’ordine di inserimento del primo elenco.

Sintassi
differenceLists(<parameters>)
Parametri
table 0-row-3 1-row-3 2-row-3
Parametro Tipo Descrizione
elenco 1 listString, listInteger, listDecimal, listBoolean, listDuration, listDateTime, listDateTimeOnly o listDateOnly Elenco da cui sottrarre.
elenco 2 Stesso tipo dell’elenco 1. Elenco di voci da rimuovere dall’elenco 1.
Firme e tipi restituiti

differenceLists(listString,listString): listString

differenceLists(listInteger,listInteger): listInteger

differenceLists(listDecimal,listDecimal): listDecimal

differenceLists(listBoolean,listBoolean): listBoolean

differenceLists(listDuration,listDuration): listDuration

differenceLists(listDateTime,listDateTime): listDateTime

differenceLists(listDateTimeOnly,listDateTimeOnly): listDateTimeOnly

differenceLists(listDateOnly,listDateOnly): listDateOnly

Esempi
code language-json
differenceLists(['a','b','c'], ['b'])

Restituisce ['a','c'].

code language-json
differenceLists(['a','a','b'], [])

Restituisce ['a','b'].

code language-json
differenceLists([], ['a'])

Restituisce [].

distinct distinct

Restituisce i valori o gli oggetti distinti di un elenco specifico. Le voci Null vengono ignorate.

Sintassi
distinct(<parameters>)
Parametri
table 0-row-3 1-row-3 2-row-3
Parametro Tipo Descrizione
listToProcess listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly o listObject Elenco da elaborare. Per listObject, deve essere un riferimento di campo.
keyAttributeName stringa Questo parametro è facoltativo e solo per listObject. Se il parametro non viene fornito, un oggetto viene considerato duplicato se tutti gli attributi hanno gli stessi valori. In caso contrario, un oggetto viene considerato duplicato se l’attributo specificato ha lo stesso valore.
Firme e tipi restituiti

distinct(<listInteger>)

Restituisce un elenco di numeri interi.

distinct(<listDecimal>)

Restituisce un elenco di decimali.

distinct(<listString>)

Restituisce un elenco di stringhe.

distinct(<listDateTimeOnly>)

Restituisce un elenco di date senza considerare il fuso orario.

distinct(<listDateTime>)

Restituisce un elenco di date.

distinct(<listDateOnly>)

Restituisce un elenco di date.

distinct(<listBoolean>)

Restituisce un elenco di booleani.

distinct(<listDuration>)

Restituisce un elenco di durate.

distinct(<listObject>)

distinct(<listObject>,<string>)

Restituisce un elenco di oggetti.

Esempi

distinct([10,2,10,null])

Restituisce [10, 2].

distinctWithNull distinctWithNull

Restituisce i valori o gli oggetti distinti di un elenco specifico. Se l’elenco include almeno una voce Null, nell’elenco restituito sarà presente una voce Null.

Sintassi
distinctWithNull(<parameters>)
Parametri
table 0-row-3 1-row-3
Parametro Tipo Descrizione
listToProcess listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly Elenco da elaborare.
Firme e tipi restituiti

distinctWithNull(<listInteger>)

Restituisce un elenco di numeri interi.

distinctWithNull(<listDecimal>)

Restituisce un elenco di decimali.

distinctWithNull(<listString>)

Restituisce un elenco di stringhe.

distinctWithNull(<listDateTimeOnly>)

Restituisce un elenco di date senza considerare il fuso orario.

distinctWithNull(<listDateTime>)

Restituisce un elenco di date.

distinctWithNull(<listDateOnly>)

Restituisce un elenco di date.

distinctWithNull(<listBoolean>)

Restituisce un elenco di booleani.

distinctWithNull(<listDuration>)

Restituisce un elenco di durate.

Esempi

distinctWithNull([10,2,10,null])

Restituisce [10, 2, null]

Nota: Il parametro <listObject> non è supportato in questa funzione.

filter filter

Restituisce un oggetto listObject con oggetti il cui attributo chiave corrisponde a uno dei valori chiave specificati.

Sintassi
filter(<parameters>)
Parametri
table 0-row-3 1-row-3 2-row-3 3-row-3
Parametro Tipo Descrizione
listToFilter listObject elenco di oggetti da filtrare. Deve essere un riferimento di campo.
keyAttributeName stringa nome attributo negli oggetti dell’elenco specificato, utilizzato come chiave per il filtro
keyValueList list array di valori chiave per il filtro
Firme e tipi restituiti

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)

Restituisce un oggetto listObject.

Esempi

Ecco un esempio di payload passato in un evento in ingresso “myevent”:

code language-json
"productListItems": [{
   "id": "product1",
   "name": "the product 1",
   "price": 20
},{
   "id": "product2",
   "name": "the product 2",
   "price": 30
},{
   "id": "product3",
   "name": "the product 3",
   "price": 50
}]

È possibile utilizzare la seguente espressione:

code language-json
filter(
 @event{myevent.productListItems},
 "id",
 ["product2", "product3", "product4"]
)

Restituisce un oggetto listObject contenente i due oggetti con “product2” e “product3” come id.

getListItem getListItem

Restituisce l’elemento dell’elenco in corrispondenza dell’indice specificato.

Sintassi
getListItem(<parameters>)
Parametri
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
Parametro Tipo
list listString
list listBoolean
list listInteger
list listDecimal
list listDuration
list listDateTime
list listDateTimeOnly
list listDateOnly
index intero
Firme e tipo restituito

getListItem(<listInteger>,<index>)

Restituisce un numero intero.

getListItem(<listDecimal>,<index>)

Restituisce un valore decimale.

getListItem(<listString>,<index>)

Restituisce una stringa.

getListItem(<listDateTimeOnly>,<index>)

Restituisce un valore datetime senza considerare il fuso orario.

getListItem(<listDateTime>,<index>)

Restituisce un valore datetime.

getListItem(<listDateOnly>,<index>)

Restituisce un elenco di date.

getListItem(<listBoolean>,<index>)

Restituisce un valore booleano.

getListItem(<listDuration>,<index>)

Restituisce una durata.

Esempi

getListItem([10, 2, 3], 1)

Restituisce “2”

getListItem(["A", "B", "C"], 2)

Restituisce “C”

Esempi con un campo evento “event.appVersion” con valore: “20.45.2.3434”

split(@event{event.appVersion}, "\\.")

Restituisce ["20", "45", "2", "3434"]

getListItem(split(@event{event.appVersion}, "\\."), 0)

Restituisce “20”

in in

Controlla se il primo valore di argomento è presente nell’elenco. Il controllo viene eseguito tramite un valore Uguale su ciascun argomento. Restituisce true se viene trovato il valore dell’argomento, in caso contrario false.

Il tipo di <expression> deve corrispondere agli elementi dell’elenco. I tipi di elementi dell’elenco, come promemoria, devono corrispondere tra loro.

Sintassi
in(<parameters>)
Parametri
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
Parametro Tipo
Stringa Stringa
Booleano Booleano
Intero Intero
Decimale Decimale
Durata Durata
Data e ora Data e ora
DateTimeOnly DateTimeOnly
Elenco listString
Elenco listBoolean
Elenco listInteger
Elenco listDecimal
Elenco listDuration
Elenco listDateTime
Elenco listDateTimeOnly
Elenco listDateOnly
Firma e tipo restituito

in(<integer>,<listInteger>)

in(<decimal>,<listDecimal>)

in(<string>,<listString>)

in(<boolean>,<listBoolean>)

in(<dateTimeOnly>,<listDateTimeOnly>)

in(<dateTime>,<listDateTime>)

in(<dateOnly>,<listDateOnly>)

in(<duration>,<listDuration>)

Restituisce un valore booleano.

Esempi

in(4,[4,5,3,4])

Restituisce true.

in(8,[4,5,3,4])

Restituisce false.

in(#{ExperiencePlatform.ProfileFieldGroup.profile.person.gender}, ["male"])

intersect intersect

Restituisce i valori comuni nei due elenchi di input. Se uno dei due elenchi è nullo, restituisce un elenco vuoto.

Sintassi
intersect(<parameters>)
Parametri
table 0-row-2 1-row-2 2-row-2
Parametro Tipo
elenco 1 list
elenco 2 list
Firme e tipi restituiti

intersect(listString,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): listBoolean

Restituisce un elenco.

Esempi
code language-json
intersect(
    ["sports", "news", "documentary"],
    ["sports", "movies", "documentary"]
)

Restituisce [“sport”, “news”]

code language-json
intersect(
    #{ExperienceDataPlatform.profile.interests},
    ["sports", "documentary"]
)

Restituisce elementi comuni tra gli attributi del profilo e un elenco specifico di categorie.

code language-json
intersect(
    #{ExperienceDataPlatform.profile.interests},
        @event{myEvent.sport_interests}
)

Restituisce elementi comuni tra gli attributi del profilo e il campo evento specificato.

limit limit

Restituisce il primo o l’ultimo N elemento di un elenco.

Sintassi
limit(<parameters>)
Parametri
table 0-row-3 1-row-3 2-row-3 3-row-3
Parametro Tipo Descrizione
listToProcess listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly o listObject Elenco da considerare. Per listObject, deve essere un riferimento di campo.
numberOfItems intero Numero di elementi da restituire dall’elenco specificato.
firstOrLastItems booleano Questo parametro è facoltativo (true per impostazione predefinita). true restituisce i primi elementi. false restituisce gli ultimi elementi.
Firma e tipo restituito

limit(<listString>,<integer>)

limit(<listString>,<integer>,<boolean>)

Restituisce un elenco di stringhe.

limit(<listInteger>,<integer>)

limit(<listInteger>,<integer>,<boolean>)

Restituisce un elenco di numeri interi.

limit(<listDecimal>,<integer>)

limit(<listDecimal>,<integer>,<boolean>)

Restituisce un elenco di decimali.

limit(<listBoolean>,<integer>)

limit(<listBoolean>,<integer>,<boolean>)

Restituisce un elenco di booleani.

limit(<listDateOnly>,<integer>)

limit(<listDateOnly>,<integer>,<boolean>)

Restituisce un elenco di date.

limit(<listDateTimeOnly>,<integer>)

limit(<listDateTimeOnly>,<integer>,<boolean>)

Restituisce un elenco di date senza considerare il fuso orario.

limit(<listDateTime>,integer>)

limit(<listDateTime>,<integer>,<boolean>)

Restituisce un elenco di date.

limit(<listDuration>,<integer>)

limit(<listDuration>,<integer>,<boolean>)

Restituisce un elenco di durate.

limit(<listObject>,<integer>)

limit(<listObject>,<integer>,<boolean>)

Restituisce un elenco di oggetti.

Esempi

limit(["A", "B", "C", "D", "E"], 3)

Restituisce ["A","B","C"].

limit(["A", "B", "C", "D", "E"], 3, false)

Restituisce ["C","D","E"].

listSize listSize

Conta il numero di elementi nell’elenco.

Sintassi
listSize(<parameters>)
Parametri
table 0-row-3 1-row-3
Parametro Tipo Descrizione
listToProcess listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly o listObject Elenco da elaborare. Per listObject, deve essere un riferimento di campo. Un listObject non può contenere un oggetto null.
Firme e tipo restituito

listSize(<listInteger>)

listSize(<listDecimal>)

listSize(<listString>)

listSize(<listBoolean>)

listSize(<listDateTimeOnly>)

listSize(<listDateTime>)

listSize(<listDateOnly>)

listSize(<listDuration>)

Restituisce un numero intero.

listSize(<listObject>)

Esempi

listSize([10,2,3])

Restituisce 3.

listSize(@event{my_event.productListItems})

Restituisce il numero di oggetti nella matrice di oggetti specificata (tipo listObject).

mergeLists mergeLists

Combina due elenchi. Quando deduplicate è true, restituisce l’unione dei due elenchi con i valori duplicati rimossi. Quando deduplicate è false, restituisce la concatenazione dei due elenchi (elementi dell’elenco 1 seguiti da elementi dell’elenco 2), mantenendo i duplicati. Le voci nulle vengono ignorate.

Nota: il parametro deduplicate deve essere un valore letterale true o false, non un’espressione booleana dinamica.

Sintassi
mergeLists(<parameters>)
Parametri
table 0-row-3 1-row-3 2-row-3 3-row-3
Parametro Tipo Descrizione
elenco 1 listString, listInteger, listDecimal, listBoolean, listDuration, listDateTime, listDateTimeOnly o listDateOnly Primo elenco. I relativi elementi vengono aggiunti per primi al risultato.
elenco 2 Stesso tipo dell’elenco 1. Secondo elenco. I suoi elementi vengono aggiunti dopo quelli dell’elenco 1.
deduplicare valore letterale booleano true restituisce l’unione di entrambi gli elenchi con i duplicati rimossi. false restituisce la concatenazione di entrambi gli elenchi, mantenendo i duplicati. Deve essere un valore letterale true o false.
Firme e tipi restituiti

mergeLists(listString,listString,boolean): listString

mergeLists(listInteger,listInteger,boolean): listInteger

mergeLists(listDecimal,listDecimal,boolean): listDecimal

mergeLists(listBoolean,listBoolean,boolean): listBoolean

mergeLists(listDuration,listDuration,boolean): listDuration

mergeLists(listDateTime,listDateTime,boolean): listDateTime

mergeLists(listDateTimeOnly,listDateTimeOnly,boolean): listDateTimeOnly

mergeLists(listDateOnly,listDateOnly,boolean): listDateOnly

Esempi
code language-json
mergeLists(['a','b'], ['b','c'], true)

Restituisce ['a','b','c'].

code language-json
mergeLists(['a','b'], ['b','c'], false)

Restituisce ['a','b','b','c'].

serializeList serializeList

Converte un elenco specifico (qualsiasi tipo eccetto listObject) in una stringa.

Sintassi
serializeList(<parameters>)
Parametri
table 0-row-3 1-row-3 2-row-3 3-row-3
Parametro Tipo Descrizione
listToProcess listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly Elenco da convertire in stringa.
separatore stringa Separatore tra ciascun elemento elenco nella stringa di output.
addQuotes booleano Questo parametro indica se ogni elemento nella stringa di output deve includere virgolette (true) o meno (false).
Firma e tipo restituito

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>)

Restituisce una stringa.

Esempi

serializeList(["Hello","World"], " ", false)

Restituisce “Hello World”.

serializeList(["Hello", "World"], ",", true)

Restituisce ““Hello”,“World””.

ordina sort

Ordina un elenco di valori o oggetti nell’ordine naturale.

Sintassi
sort(<parameters>)
Parametri
table 0-row-3 1-row-3 2-row-3 3-row-3
Parametro Tipo Descrizione
listToSort listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly o listObject Elenco da ordinare. Per listObject, deve essere un riferimento di campo.
keyAttributeName stringa Questo parametro è solo per listObject. Il nome dell’attributo negli oggetti dell’elenco specificato viene utilizzato come chiave per l’ordinamento.
ordinamentoOrdine booleano Crescente (true) o Decrescente (false)
Firma e tipo restituito

sort(<listInteger>,<boolean>)

Restituisce un elenco di numeri interi.

sort(<listDecimal>,<boolean>)

Restituisce un elenco di decimali.

sort(<listString>,<boolean>)

Restituisce un elenco di stringhe.

sort(<listDateTimeOnly>,<boolean>)

Restituisce un elenco di date senza considerare il fuso orario.

sort(<listDateTime>,<boolean>)

Restituisce un elenco di date.

sort(<listDateOnly>,<boolean>)

Restituisce un elenco di date.

sort(<listBoolean>,<boolean>)

Restituisce un elenco di booleani.

sort(<listObject>,<string>,<boolean>)

Restituisce un elenco di oggetti.

Esempi

sort(["A", "C", "B"], true)

Restituisce ["A","B","C"].

sort([1, 3, 2], false)

Restituisce [3, 2, 1].

sort(@event{my_event.productListItems}, "SKU", true)

Restituisce l’oggetto listObject ordinato in base all’attributo SKU (ordine crescente)

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 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) or distinctWithNull (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, and sort to 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 deduplicate parameter (product-specific)
  • differenceLists: A set operation returning the items of the first list that are not present in the second list (product-specific)

Guardrails:

  • distinctWithNull does not support the <listObject> parameter type
  • filter requires the listObject parameter to be a field reference, not an inline literal
  • listSize on a listObject requires the list to be a field reference; a listObject cannot contain null objects
  • serializeList does not support the listObject type
  • mergeLists and differenceLists only support scalar list types (string, integer, decimal, boolean, dateTime, dateTimeOnly, dateOnly, duration); listObject is not supported
  • mergeLists’s deduplicate parameter must be a literal true/false, not a dynamic boolean expression
  • differenceLists always 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” with false (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) or limit(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 distinct and distinctWithNull? — distinct ignores null values and excludes them from the result; distinctWithNull treats 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, filter only works on listObject; for scalar lists use in or distinct for 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 of list1 not present in list2.
  • Q: What is the difference between intersect and differenceLists? — intersect returns items common to both lists; differenceLists returns items in the first list that are absent from the second list.
recommendation-more-help
journey-optimizer-help