Skip to main content
2/5

wherecontains(): count how many times a value appears

Easy

Return how many times ri!value appears in the list.

You already have a way to get every position. Counting them is counting the occurrences.

Inputs

  • ri!items: List of Text
  • ri!value: Text

ri! Rule Inputs

ri!itemsList of Text
{
  "a",
  "b",
  "b"
}
ri!valueText
"b"

Example 1: Twice

Input: ri!items
{
  "a",
  "b",
  "b"
}
Input: ri!value
"b"
Expected output:
2

Example 2: Once

Input: ri!items
{
  "a",
  "b"
}
Input: ri!value
"b"
Expected output:
1

Example 3: Never

Input: ri!items
{
  "a",
  "c"
}
Input: ri!value
"b"
Expected output:
0

Example 4: Every item matches

Input: ri!items
{
  "x",
  "x",
  "x"
}
Input: ri!value
"x"
Expected output:
3

Example 5: An empty list

Input: ri!items
{}
Input: ri!value
"b"
Expected output:
0

Appian Expression Tips

  • • Use ri!variableName for rule inputs
  • • Use a!localVariables(local!x: …, body) for locals
  • • Use a!forEach(items: …, expression: fv!item) to iterate
  • • Use where() / reject(fn!isnull, list) to filter