Use If() Expression for Inline Conditions
Using the out-of-box Condition action allows developers to construct If-this-then-that logic, which allows for business process rules to be implemented within a workflow. While this approach works, it takes up a lot of real estate and impacts developer productivity based on the amount of scrolling involved when designing logic apps. If you had to use a Condition action for all decisions, you would have a very large and unmanageable logic app.
For example, we want to compare two values and construct a message through a Compose action. If the CurrentValue is greater than our BaselineValue then we want to compose a message of higher, else we will Compose a message of lower.
An alternative approach is to use the If() expression. We essentially can reproduce the same logic, but within a single-line expression. Our expression looks like the following:
If we closely examine our expression, we will discover that we have a nested expression that includes the greater expression. The greater expression will compare our CurrentValue variable with our BaselineValue variable and return true or false. The If expression will now evaluate the boolean response. If the value of the greater expression is true, then the first value (higher) will be returned, else, the second (lower) value will be returned.
The result is our condition logic is embedded within our Compose action and looks like the following:
In the scenario we explored, either approach will functionally work. However, if we consider that our logic was rather simple, consuming a lot of real estate in the logic app designer doesn’t scale well if we have a lot of conditions contained in our workflow. Now, the flip side is that if we use the If() expression too much, we lose readability/visibility by having a lot of logic embedded within actions as expressions, so that is something that should be considered as well.