2/5

a!localVariables(): show the price range of a product

Medium

A shop listing shows each product's price range across its variants:

  • variants at different prices — "From $9 to $25"
  • every variant at one price — just that price: "$12"
  • no variants — "Unavailable"

The lowest and highest prices are each needed more than once: to compare them, and to write them out. Work each out once and name it.

Input

  • ri!prices — List of Integer

ri! Rule Inputs

ri!pricesList of Integer
{
  25,
  9,
  14
}

Example 1 — Three variants

Input: ri!prices
{
  25,
  9,
  14
}
Output:
"From $9 to $25"

Example 2 — A single variant

Input: ri!prices
{12}
Output:
"$12"

Example 3 — Two variants, one price

Input: ri!prices
{
  7,
  7
}
Output:
"$7"

Example 4 — Nothing to sell

Input: ri!prices
{}
Output:
"Unavailable"

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