1/5

index(): read one item safely by position

Easy

Return the item at ri!position. When that position does not exist, return "none" rather than failing.

Positions count from 1, and the list may be empty.

Inputs

  • ri!items — List of Text
  • ri!position — Integer

ri! Rule Inputs

ri!itemsList of Text
{
  "a",
  "b",
  "c"
}
ri!positionInteger
2

Example 1 — The second item

Input: ri!items
{
  "a",
  "b",
  "c"
}
Input: ri!position
2
Output:
"b"

Example 2 — The first item

Input: ri!items
{
  "a",
  "b",
  "c"
}
Input: ri!position
1
Output:
"a"

Example 3 — Past the end

Input: ri!items
{
  "a",
  "b"
}
Input: ri!position
9
Output:
"none"

Example 4 — Position zero does not exist

Input: ri!items
{
  "a",
  "b"
}
Input: ri!position
0
Output:
"none"

Example 5 — An empty list has nothing at any position

Input: ri!items
{}
Input: ri!position
1
Output:
"none"

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