5/5

index(): summarise every shipment on a tracking page

Hard

A tracking page lists every shipment in an order with a one-line summary.

Each shipment is a record with an id and an events list of status updates, oldest first. A shipment that has not been dispatched has no events field at all.

Return one line per shipment, in order

  • several updates — the first, the latest and how many: "S-1: Placed -> Delivered (3 updates)"
  • one update — "S-2: Placed"
  • no updates, or no events field — "S-3: No updates yet"

Watch out

  • Reading a field the record does not have gives back the default you pass to index(), so choose one that behaves like an empty list.
  • The latest update sits at the last position, which is the length of the list.

Tip: each shipment's events are needed several times. a!localVariables() lets you name them; repeating the expression works too.

Input

  • ri!shipments — List of Map

ri! Rule Inputs

ri!shipmentsList of Map
{
  a!map(id: "S-1", events: {"Placed", "Packed", "Delivered"}),
  a!map(id: "S-2", events: {"Placed"}),
  a!map(id: "S-3", events: {})
}

Example 1 — Three shipments at different stages

Input: ri!shipments
{
  a!map(id: "S-1", events: {"Placed", "Packed", "Delivered"}),
  a!map(id: "S-2", events: {"Placed"}),
  a!map(id: "S-3", events: {})
}
Output:
{
  "S-1: Placed -> Delivered (3 updates)",
  "S-2: Placed",
  "S-3: No updates yet"
}

Example 2 — Not dispatched, so no events field

Input: ri!shipments
{a!map(id: "S-4")}
Output:
{"S-4: No updates yet"}

Example 3 — Two updates

Input: ri!shipments
{a!map(id: "S-5", events: {"Placed", "Cancelled"})}
Output:
{"S-5: Placed -> Cancelled (2 updates)"}

Example 4 — No shipments

Input: ri!shipments
{}
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