4/5

index(): turn survey answers into labels

Medium

A feedback survey stores each answer as the position of the option chosen from ri!options: choosing the third option saves 3. Turn one person's answers into labels, in question order:

  • a position in the options — that option's label
  • 0 — the question was skipped: "Skipped"
  • a position past the end — that option has since been removed from the survey: "(removed)"

Each answer is handled on its own, so one odd answer never spoils the rest.

Inputs

  • ri!options — List of Text
  • ri!answers — List of Integer

ri! Rule Inputs

ri!optionsList of Text
{
  "Poor",
  "Okay",
  "Great"
}
ri!answersList of Integer
{
  3,
  1
}

Example 1 — Two answers, in question order

Input: ri!options
{
  "Poor",
  "Okay",
  "Great"
}
Input: ri!answers
{
  3,
  1
}
Output:
{
  "Great",
  "Poor"
}

Example 2 — A skipped question

Input: ri!options
{
  "Poor",
  "Okay",
  "Great"
}
Input: ri!answers
{0}
Output:
{"Skipped"}

Example 3 — A mix of all three

Input: ri!options
{
  "Poor",
  "Okay",
  "Great"
}
Input: ri!answers
{
  3,
  0,
  4
}
Output:
{
  "Great",
  "Skipped",
  "(removed)"
}

Example 4 — No answers

Input: ri!options
{
  "Poor",
  "Okay",
  "Great"
}
Input: ri!answers
{}
Output:
{}

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