a!forEach(): list the invoices that need a reminder
Medium
Accounts sends a reminder for every invoice that is 30 or more days overdue. Given the open invoices, return one reminder line per overdue invoice, in their original order: "INV-7: 45 days overdue".
Watch out
- Invoices under 30 days are left out entirely, not replaced by an empty line.
- An iteration that returns
{}contributes nothing, so the result can be shorter than the input.
Input
ri!invoices— List of Map, each withnumber(Text) anddaysOverdue(Integer)
ri! Rule Inputs
ri!invoicesList of Map{
a!map(number: "INV-7", daysOverdue: 45),
a!map(number: "INV-8", daysOverdue: 10)
}Example 1 — Some overdue, some not
Input: ri!invoices
{
a!map(number: "INV-7", daysOverdue: 45),
a!map(number: "INV-8", daysOverdue: 10),
a!map(number: "INV-9", daysOverdue: 60)
}Output:
{
"INV-7: 45 days overdue",
"INV-9: 60 days overdue"
}Example 2 — Exactly 30 days gets a reminder
Input: ri!invoices
{a!map(number: "INV-3", daysOverdue: 30)}Output:
{"INV-3: 30 days overdue"}Example 3 — Nothing overdue yet
Input: ri!invoices
{
a!map(number: "INV-4", daysOverdue: 29),
a!map(number: "INV-5", daysOverdue: 0)
}Output:
{}Example 4 — No open invoices
Input: ri!invoices
{}Output:
{}Appian Expression Tips
- • Use
ri!variableNamefor 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