4/5

wherecontains(): unsubscribe every copy of an address

Medium

A mailing list built from several imports can hold the same address more than once. When someone unsubscribes, every copy of their address has to go; everyone else stays, in their original order.

remove(list, positions) deletes by position, and wherecontains() gives you every position of a value at once.

Inputs

  • ri!subscribers — List of Text
  • ri!address — Text

ri! Rule Inputs

ri!subscribersList of Text
{
  "ann@example.com",
  "bo@example.com",
  "ann@example.com"
}
ri!addressText
"ann@example.com"

Example 1 — Two copies of the address

Input: ri!subscribers
{
  "ann@example.com",
  "bo@example.com",
  "ann@example.com"
}
Input: ri!address
"ann@example.com"
Output:
{"bo@example.com"}

Example 2 — Not subscribed at all

Input: ri!subscribers
{
  "bo@example.com",
  "cy@example.com"
}
Input: ri!address
"ann@example.com"
Output:
{
  "bo@example.com",
  "cy@example.com"
}

Example 3 — The only subscriber leaves

Input: ri!subscribers
{"ann@example.com"}
Input: ri!address
"ann@example.com"
Output:
{}

Example 4 — An empty list

Input: ri!subscribers
{}
Input: ri!address
"ann@example.com"
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