What is the difference between the len(), count(), and length() functions in Appian, and when should each be used?
Answer
len(), length(), and count() look similar because they all return a size. They work on different things, though: len() takes text, while length() and count() take lists.
1. len(): count characters in text
len() returns the number of characters in a text value, including spaces.
Example:
Output: 11
A practical use is validating a username that must not exceed 20 characters:
If the username has more than 20 characters, the expression returns "Username too long". Otherwise it returns "Valid".
2. length(): count non-null elements in a list
length() returns the number of non-null elements in a list.
Output: 3
A list containing a null value:
Output: 2
The list has three positions, but only two hold values, so length() returns 2.
3. count(): count elements, including nulls
count() returns the total number of items in the supplied array or arrays, including null elements.
A list without null values:
Output: 3
A list containing a null value:
Output: 4
All four elements are counted, including the null.
Quick comparison
Expression | Output | Explanation |
|---|---|---|
|
| Counts characters in text |
|
| Counts non-null elements |
|
| Excludes the null element |
|
| Includes the null element |
For more information ref Appian Docs:
https://docs.appian.com/suite/help/26.9/fnc_text_len.html
https://docs.appian.com/suite/help/26.9/fnc_statistical_count.html
https://docs.appian.com/suite/help/26.9/fnc_array_length.html
Try it yourself
Change the inputs or the expression and run it to see what it returns.
Independent evaluator: it approximates the Appian expression language and may differ from a real Appian environment. Verify anything that matters. Terms