I am looking for an efficient, one trigger methodology to deal with the initial app condition of an object list being empty, wherein the following expression does not compute and cannot be used.
map_to_text_list(@Variable.Scan Output List with Quantity , ‘Scan Output’)
I was thinking perhaps to wrap this in the LINK() function, but not sure how to structure the second argument in that function to match the array data type of the first argument…
Hi Jmlowden, thanks for reaching out about the issue with map_to_text_list() not computing when the object list is empty.
This behavior occurs because map_to_text_list() expects at least one element in the object list to function properly. When the list is empty, the expression doesn’t return a value, which can lead to unexpected results.
To handle this scenario within a single trigger, you can implement a conditional check:
Use the IF function to determine if the object list is empty:
IF(@Variable.Scan Output List with Quantity = [], 'No items to display', map_to_text_list(@Variable.Scan Output List with Quantity, 'Scan Output'))
This expression checks if the object list is empty. If it is, it returns a default message like ‘No items to display’. Otherwise, it proceeds with your original map_to_text_list() expression.
This approach ensures that map_to_text_list() is only called when the object list has elements, preventing potential errors.
For more details on working with expressions involving arrays and objects, you can refer to the following documentation:
Let me know if this resolves your issue or if you need further assistance exploring alternative methods, such as using the LINK() function.
Also, in your example, would the difference between the data format single value “message” format if true and the array output format if false cause another problem?
Hi James, sorry for the mix-up with my first suggestion about IF().
map_to_text_list() fails because it receives a null list, not an array.
Build an empty-safe list.
array_concat(@Variable.Scan Output List with Quantity, @Variable.Scan Output List with Quantity)
Pick the first non-null array.
link(@Variable.Scan Output List with Quantity, array_concat(@Variable.Scan Output List with Quantity, @Variable.Scan Output List with Quantity))
Convert to text.
map_to_text_list(
link(@Variable.Scan Output List with Quantity,
array_concat(@Variable.Scan Output List with Quantity, @Variable.Scan Output List with Quantity)),
'Scan Output'
)
Drop any IF check. IF still evaluates the null list and errors.
LINK stops at the first real array, so map_to_text_list always gets at least [].
array_concat treats a null input as an empty array [] so concatenating two null lists returns [] instead of throwing an error. An upcoming platform release (r324) will extend the same null-safe behavior to all MAP_TO_X_LIST functions, which will simply return an empty list when the source array is null.
Hey @jmlowden, there is not currently a way to construct empty lists, objects or object list within the expression editor. It is only possible to create static string, number, integer, and boolean lists in expressions. The syntax looks like the following: