Skip to main content
Question

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:

len("Appianverse")

Output: 11


A practical use is validating a username that must not exceed 20 characters:

if(
len(ri!username) > 20,
"Username too long",
"Valid"
)

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.

length({10, 20, 30})

Output: 3


A list containing a null value:

length({10, null, 30})

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:

count({1, 2, 3})

Output: 3


A list containing a null value:

count({1, 2, 3, null})

Output: 4


All four elements are counted, including the null.


Quick comparison

Expression

Output

Explanation

len("Appianverse")

11

Counts characters in text

length({10, 20, 30})

3

Counts non-null elements

length({10, null, 30})

2

Excludes the null element

count({1, 2, 3, null})

4

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.

ri!data=
ri!name=

Independent evaluator: it approximates the Appian expression language and may differ from a real Appian environment. Verify anything that matters. Terms

JuniorExpressions#coding#sailcoding#function