Logical Functions in Appian

Is Your AI and Automation Strategy Right for You?

Take the Assessment now!

Logical functions are basic building blocks in any business logic, and it's important to understand their behaviour to use them effectively. The functions if, or, and, as well as toboolean do some magic in the background that you should be aware of. Here a quick test for you, if any of the results surprise you, it's worth to continue reading:

a!map(
  "1": if(null, true, false),
  "2": if({}, true, false),
  "3": if({true, false}, true, false),
  "4": if(false, true, false, 1, 2),
  "5": or(null), 
  "6": or({}),
  "7": and(null),
  "8": toboolean(0),
  "9": toboolean(1),
  "10": toboolean(-1)
)

The results are in :)

a!map(
  '1': false,
  '2': {},
  '3': {true, false},
  '4': 2,
  '5': false,
  '6': false,
  '7': true,
  '8': false,
  '9': true,
  '10': true
)

The if Function

Probably, the first statement was trivial as we often come across this case. Null values are considered to be false. This is actually only true in the case of the if statement, otherwise null is always handled separately as we will see in a bit.

For the second and third statement we already have to look deeper into the documentation since the function definition in the Appian designer doesn't cover this behaviour. In the docs we discover that the if statement can work with lists as conditions. That can be super helpful, but it's also something to watch out for as this implicit behaviour can also lead to bugs that are not as obvious.

I included statement four just as an Easter egg as it's not covered in the documentation at all. It's possible to write nested if statements like this, but since it's not officially documented, you should always prefer a!match

The and/or Function

With our knowledge from the if, we are now ready to tackle and and or. Statement five makes sense: If null is false, or(null) will be false too, but then looking at and(null) we start scratching our heads. Shouldn't this be false too? What is going on here?

Again, this behaviour is only described in the more detailed documentation (see and/or). Under the hood these functions remove all null values before evaluating. For the or an empty list is evaluated to false and for and to true. Keeping this in mind is important as it can easily lead to some unintuitive results:

a!localVariables: {
    local!people: {
        a!map(
            name: "Peter",
            isAdult: true
        ),
        a!map(
            name: "Ryan",
            isAdult: null
        )
    },
    local!everyoneIsAdult: and(local!people.isAdult)
}

This would evaluate to true, although I think the intuitive result should be false or null. One way to avoid this, is to use a comparison and(toboolean(local!people.isAdult) = true) or to ensure that the data is well defined.

The toboolean Function

I included this function as we use it like above without knowing how values are parsed by toboolean. In comparison, to the logical functions discussed before, this one comes with the complete documentation in the designer and describes quite a lot of ways on how it will parse a value and turns it into a boolean:

Converts a value or values to Boolean. toboolean(1) returns true. toboolean({1, 0}) returns {true, false}. Any text value beginning with "t" or "T", or any non-zero integer value, returns true. All other values return false.

Conclusion

Overall, we can conclude that a closer view into Appian documentations, provides us with quite some extra bits of knowledge of functions we use day in, day out. I hoped you learned something and let me know in the comments if you were ever caught out by this behaviour of the logical functions.

Banner Image