Sometimes one function is not enough, so combining multiple is necessary. To help us with that, we have the “and” function. It combines various functions that return a boolean value and return “true” if all of them return “true”. If even one returns “false” then it will return “false”.

Simple enough, but let’s explore it.

Usage

It follows a simple pattern.

  1. Expression 1
  2. ….

You can have more than two, but you need to have at least two expressions.

Example:

and(true,true)

will return 

true

How about if we include a “false”?

and(true,true,true,true,false)

will return 

false

Even if there are a lot of “true” values, if we have even one “false” the function will return “false”.

Let’s look at more practical examples. Let’s think about a variable that contains an integer, and we want to check if the value is between 0 and 10. We can use the “if” function, combined with the “lessOrEquals” and “greaterOrEquals” function to get the result. Our “and” function brings all of them together.

value for the variable variables('TEST_INT') is 3

if(and(lessOrEquals(variables('TEST_INT'),10),greaterOrEquals(variables('TEST_INT'),1)),'We have our number','out of range')

will return 

"We have our number"

Notice that when we can build the function by thinking of what we need:

I want to check IF a VARIABLE has a number that is LESS OR EQUALS than 10 AND GREATER OR EQUALS than 1

You could even do it without the “if” function.

and(lessOrEquals(variables('TEST_INT'), 10), greaterOrEquals(variables('TEST_INT'), 1))

will return

true

Ensure that the functions or variables always return a boolean; otherwise, Power Automate will error. For example:

and(true,'test')

will return an error

Here’s the error:

Unable to process template language expressions in action 'Compose' inputs at line '1' and column '4722': 'The template language function 'and' expects all of its parameters to be booleans. Found invalid parameter types: 'String'.'.

The error message is relatively straightforward, so it’s easier to find the offending parameter.

Limitations

I don’t know about a documented limitation, but I want to know about it if you have a good example. Would you mind emailing me or interacting on Twitter?

Recommendations:

Here are some things to keep in mind.

Divide to conquer

It’s possible to nest “and” functions, and it may make sense. For example, you can have “or” functions that can control parts of the conditions.

I only warn caution because expressions can become significant and unmanageable quickly. Also, it’s hard to debug, so I would recommend having separate conditions in logical “blocks” if you can, of course. Debugging is a lot easier in this case.

Sources:

Microsoft’s “and” Function Reference

Back to the Power Automate Function Reference.

Photo by TJ Arnold on Unsplash

Manuel Gomes

I'm a Project Manager with experience in large projects and companies. I've worked in the past for companies like Bayer, Sybase (now SAP) and I'm currently working for Pestana Hotel Group.

View all posts by Manuel Gomes →

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: