All functions

Appian a!match()

Choose a result by matching one value against a list of conditions. The flat replacement for nested if(), where the first match wins and the order of ranges decides the answer.

Official Appian documentation

The shape

a!match() takes one value and a list of conditions, each followed by what to return when it matches, then a default for when nothing does.

a!match(
  value: status,
  equals: "O", then: "Open",
  equals: "C", then: "Closed",
  default: "Unknown"
)

It is the answer to the nested if() ladder from the first lesson: the same logic, written flat, one outcome per line.

Two kinds of condition

  • equals — matches when the value is exactly this
  • whenTrue — matches when a condition holds. Inside it, fv!value is the value being matched

Every condition is followed by its own then, and you can mix both kinds in one call:

a!match(
  value: score,
  whenTrue: fv!value >= 90, then: "A",
  whenTrue: fv!value >= 60, then: "C",
  default: "F"
)

fv!value also works inside then and default, so the result can use the value it matched.

First match wins, and the rest never run

Conditions are checked top to bottom. The first one that matches decides the answer, and everything after it is not evaluated at all — the same short-circuit if() has. A later branch can safely divide by something an earlier branch has already ruled out.

The trap: order decides ranges

Because the first match wins, whenTrue ranges must go from tightest to loosest. Put fv!value >= 60 above fv!value >= 90 and a 95 matches the first one it reaches and comes back as a C. Nothing is wrong with either condition; they are in the wrong order, and no error tells you.

Also worth knowing

  • equals compares text case-sensitively, so "b" does not match "B". That is the opposite of the = operator, which Appian documents as case-insensitive — so rewriting an if(x = "B", ...) as a!match() can quietly change which values match
  • default is required. Leave it off and the call fails rather than returning null
  • Every argument needs its keyword. Appian states that keywords are required, because the pairs are recognised by name

Try it

Run each one and read what comes back before moving on.

1Match a value against two exact options.

a!match(value: 2, equals: 1, then: "one", equals: 2, then: "two", default: "other")

2Give it a value none of the conditions expect.

a!match(value: 9, equals: 1, then: "one", default: "other")

1Use conditions instead of exact values. fv!value is the value being matched.

a!match(value: 75, whenTrue: fv!value >= 90, then: "A", whenTrue: fv!value >= 60, then: "C", default: "F")

2Now put the same two conditions in the wrong order and score a 95.

a!match(value: 95, whenTrue: fv!value >= 60, then: "C", whenTrue: fv!value >= 90, then: "A", default: "F")

Match text in a different case.

a!match(value: "b", equals: "B", then: "matched", default: "no match")

Put something that would fail after a condition that matches.

a!match(value: 5, equals: 5, then: "safe", equals: 1 / 0, then: "never", default: "d")

Independent evaluator — approximates the Appian expression language and may differ from a real Appian environment. Verify anything that matters. Terms

Exercises

0 of 5 cleared
  1. 1a!match(): turn a status code into a label
  2. 2a!match(): choose a parcel size from its weight
  3. 3a!match(): tell a customer whether support is open
  4. 4a!match(): days of stock left without dividing by zero
  5. 5a!match(): quote a delivery price
Start the first exercise