3/5

index(): pull one field from every record

Medium

Given a list of records, return the ri!field value from each one, in order. Records without that field contribute "unknown" so the result still lines up with the input.

This needs no loop. Handing a list of records and a field name to index() does it in one call.

Inputs

  • ri!people — List of Map
  • ri!field — Text

ri! Rule Inputs

ri!peopleList of Map
{
  a!map(name: "Ann", city: "Pune"),
  a!map(name: "Bo", city: "Delhi")
}
ri!fieldText
"name"

Example 1 — Every name

Input: ri!people
{
  a!map(name: "Ann", city: "Pune"),
  a!map(name: "Bo", city: "Delhi")
}
Input: ri!field
"name"
Output:
{
  "Ann",
  "Bo"
}

Example 2 — Every city

Input: ri!people
{
  a!map(name: "Ann", city: "Pune"),
  a!map(name: "Bo", city: "Delhi")
}
Input: ri!field
"city"
Output:
{
  "Pune",
  "Delhi"
}

Example 3 — One record is missing the field

Input: ri!people
{
  a!map(name: "Ann"),
  a!map(city: "Delhi")
}
Input: ri!field
"name"
Output:
{
  "Ann",
  "unknown"
}

Example 4 — A single record

Input: ri!people
{a!map(name: "Cy")}
Input: ri!field
"name"
Output:
{"Cy"}

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