December 20, 2024

Converting things is essential, and Power Automate has a few functions to help us in doing that. Today we’ll focus on the bool function that converts values in a boolean datatype. Ok, it’s pretty self-explanatory, but there are some things to understand.

Let’s take a look.

Usage

It follows a simple pattern.

  1. Value to convert

Let’s start with a simple example. Convert a string value.

bool(variables('STRING_TO_CONVERT'))
'this is a string'

will return an error

Since the string is not convertible to a boolean, it will return the error:

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

But if the value contains a valid string

bool('true')

will return

true

The case is not essential, so you can also provide, for example:

bool('tRUe')

will return

true

How about integers and Floats? I’ll give a bunch of values, and all will return the same values.

bool(12)
bool(-12)
bool(12.3)
bool(-12.3)

will return 

true

We know that one represents “true” and “0” means false, but we expect the above to return that value. For example,

bool(0)

will return 

false
Please be careful with this function since the “default” value looks like it’s “true”. Only use it when you know that you have something that approaches a boolean value, like the “1, 0” notation or a variation of “true, false”.

Let’s look at complex objects like arrays.

bool(variables('ARRAY_TO_CONVERT'))
createArray('1','2','3')
createArray(true,false,true)

will return an error

It’s impossible to convert an array to a boolean, even if it contains only boolean values. It will return the following error:

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

Finally, let’s see what happens when we provide a null.

bool(null)

will return an error.

The function here behaves differently as the string function, where it will return an error:

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

In this case, we need to validate if the expression inside the bool function returns null. If it does, then we cannot convert it.

Limitations

Depending on the size of your bool and nested functions, your expression may return an error, even if it’s correct. Please note that the expressions have a max size of 8,192 characters. If you have an expression that is even bigger than 1000, I would strongly advise breaking it into smaller, manageable formulas.

Recommendations:

Here are some things to keep in mind.

Please don’t do it on bools.

It’s a waste to do it on bool variables since they are already bools. So there’s no real reason to convert a value into itself, but please let me know if you know of a good reason to do it.

Don’t nest

There’s no real reason to do it, but if you find yourself in a situation where you have nested bool functions in a formula, you should review it and make everything more straightforward.

Sources:

Microsoft’s bool Function Reference

Back to the Power Automate Function Reference.

Photo by Alexander Sinn 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