When building expressions, keep in mind the following aspects of expression evaluation:
Consider the following simple expression:
=user(pp!initiator, "firstName") & " " & user(pp!initiator, "lastName")
You might expect that evaluation will proceed from left to right, and thus the
user() function returning the first name will be evaluated first, returning the first name, followed by the literal single space and concluding with the second
user() function returning the last name. However, the expression's value is the same if evaluation proceeds from right to left. It's even the same if the middle happens first and then the two
user() functions are evaluated.
This is only true if expression functions only return values and do not have side effects. A side effect is any other change in the system besides the value a function returns. None of the functions shipped with Appian have side effects. Plug-in developers must ensure their functions conform to this restriction to avoid non-deterministic behavior due to expression evaluation optimizations and compensations.
Here are a few examples of cases where functions might not run when you expect:
if() function is used in an expression, the parameter that is not selected is not evaluated.
Although configured using functions, smart services work differently. In interfaces and in certain web APIs, smart services are guaranteed to be executed exactly once. In any other expression, they are not executed. This is because executing a smart service's associated function does not by itself execute the smart service. The function merely returns the desired smart service configuration, and that in turn is executed by the framework if and only if it is in the right place (writer functions work the same way).
Functions and Side Effects