All functions

Appian if()

Return one of two values based on a condition. The first function in almost every Appian expression, and the one whose list behaviour catches people out.

Official Appian documentation

The shape

if() takes exactly three things: a condition, the value to return when it is true, and the value to return when it is false.

if(condition, valueIfTrue, valueIfFalse)

It is not a statement and it does not "do" anything. It returns a value, which is why it can sit anywhere a value can sit: inside a text concatenation, inside a list, inside another if().

Only one branch ever runs

Appian evaluates the condition first, then evaluates only the branch it needs. The other branch is never touched, so it does not matter if it would have failed.

This is the whole reason if() can guard a risky operation. Checking for zero before dividing works because the division never happens when the count is zero.

More than two outcomes

There is no else if. When you need a third outcome, you put another if() in the false slot, and keep nesting.

if(score >= 90, "A",
  if(score >= 75, "B",
    if(score >= 60, "C", "F")))

Order matters. Each condition is only reached when every condition above it was false, so you write the bands from the top down and never repeat the upper bound.

Give it a real Boolean

Comparison operators (=, <>, >, >=) and the logic functions (and(), or(), not(), isnull(), isnullorempty()) all return a Boolean. Build the condition out of those rather than relying on a number or a piece of text being treated as true.

The trap worth knowing

Comparing a list to a value gives you a list of Booleans, one per element. if() does not label each element from that. It collapses the whole list into a single answer and returns one value.

When you want one result per element, the loop belongs on the outside and the if() on the inside:

a!forEach(items: scores, expression: if(fv!item >= 60, "Pass", "Fail"))

This comes up in interviews constantly, because the collapsed version still returns a value rather than an error. Nothing tells you it is wrong except the answer.

Try it

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

Start with the plain shape. Run it, then change 5 > 3 to 5 < 3 and run it again.

if(5 > 3, "yes", "no")

1Dividing by zero is an error. Run this on its own first.

1 / 0

2Now put that same division in the branch that is not taken.

if(true, "safe", 1 / 0)

1Compare a whole list to a number and look at the type of what comes back.

{45, 72, 60} >= 60

2Hand that list straight to if() and watch it collapse.

if({45, 72, 60} >= 60, "Pass", "Fail")

3Put the loop on the outside instead.

a!forEach(items: {45, 72, 60}, expression: if(fv!item >= 60, "Pass", "Fail"))

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. 1if(): return Pass or Fail from a score
  2. 2if(): map a score to a letter grade
  3. 3if(): fall back to Guest when a name is missing
  4. 4if(): exam pass-rate status without dividing by zero
  5. 5if(): write the end-of-term report line
Start the first exercise