# Power Automate: When true is not true

The concept of “boolean” changes a bit from the platform, programming language, and framework that you’re using. Some consider it as 0 or 1, others “true” or “false,” so we need to understand how each works. In the case of Power Automate, we have two functions to provide us with the value (true and false) and one to convert to a boolean (the “bool” function).

I apologise in advance for using the word “true” way over too many times, but if I used something else could be a bit more confusing.

So today, let’s look on how to deal with boolean values, and how to avoid issues on your Flows.

## Let’s look at some examples.

First, let’s look if we compare the string “true” with the boolean value “true”. To do this, I wrote the word “true” in the left part and used the expression to get the “true” function in the left.

What is the path that you think it will take?

Here’s the solution:

Some developers would frown upon this result. The string “true” is not the same as the value “true”; however, Flow considers them the same.

Let’s now build the same comparison but using an expression:

``````equals('true',true)
``````

Let’s put it in a “Compose” action and see what happens.

The result will be this:

So the same thing but using two different strategies in Power Automate will get you two different results.

In the first case, some transformation in the “Condition” action makes it so that they are both the same. But in the case of the expression, it’s considered different because there’s no implicit conversion. If we do it with the “bool” function.

``````equals(bool('true'),true)
``````

We would get:

Let’s try with zeros and ones—first, the same example as above with the “condition” action.

And we get:

It’s a different result from before. It’s understandable because Power Automate may not know what the value “1” is but let’s continue. Without converting, we have the formula:

``````equals(1, true)
``````

And the result:

The result is consistent with the previous example. Finally, let’s convert the value “1” and see what happens.

``````equals(bool(1), true)
``````

We’ll get:

This result shows that Power Automate understands what “1” is in boolean, although in the case of the expression it cannot be converted. In the comparison, the “1” is considered the number “1” and not the “boolean value” for true. In the case of the conversion, it doesn’t matter. Both are converted correctly.

One more test. Let’s convert the string “1” to boolean.

``````equals(bool('1'),true)
``````

We get an error:

``````Unable to process template language expressions in action 'Convert_the_string_value_1' inputs at line '1' and column '4731': 'The template language function 'bool' was invoked with a parameter that is not valid. The value cannot be converted to the target type.'.
``````

This doesn’t mean that strings cannot be converted to boolean values. For example, if using the following expression:

``````equals(bool('true'),true)
``````

We get the following result.

What it means is that when we try to convert the value, we only have two possibilities (true or false), but if the value cannot be converted, it doesn’t mean it’s automatically “false.” It only means that it’s not one of the two possibilities, so the 3rd possible state is “error.”

## How to deal with it?

So what can we say about the actual value of “true”? The only thing that we can say is that the conversion using the” bool” function and the real function is consistent since, with transformation, the following values are considered “true”:

• 1
• “1”
• “true”

But if we don’t convert the above values, they are considered “true,” except if we use them in the “Compare” action.

So what can we do?

My recommendation is that the” bool” function does a great job converting the values to boolean. It’s a pity that it crashes when the value is not possible to convert, but it makes sense that Microsoft developed it like this, as we’ve seen above.

Using the true and false values Power Automate, you’ll always know that you have the correct value. If you get the value from any other place in any other format, the” bool” function is an excellent bet to convert the value.

Finally, deal with errors properly and plan for timeouts, but this rule applies to every Flow you build.

## Final thoughts

Conversion of values is complex and different systems do it differently. In this article, I tried to show you how Power Automate takes care of the conversion and considers the boolean value of “true” and not a string or a number.

Now that you know, please be careful using these values. I see these mistakes happening all the time, and they can make that your Flow runs incorrectly or that you get invalid results.

Have a suggestion of your own or disagree with something I said? Leave a comment or interact on Twitter and be sure to check out other Power Automate-related articles here.

Photo by Phil Botha on Unsplash #### Manuel Gomes

I'm a previous Project Manager, and Developer now focused on delivering quality articles and projects here on the site. I've worked in the past for companies like Bayer, Sybase (now SAP), and Pestana Hotel Group and using that knowledge to help you automate your daily tasks

View all posts by Manuel Gomes →