October 13, 2024

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 have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →

Leave a Reply

Your email address will not be published. Required fields are marked *

Mastodon