Converting things is essential, and Power Automate has a few functions to help us in doing that. Today we’ll focus on the string function that converts values in a string. 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 boolean value.

string(variables('BOOL_TO_CONVERT'))
false

will return 

'False'

Notice that we initialized the value as “false” (“f” in lower case), and the string normalized the value to “False” (“f” in upper case). So if you insert it with the first value in the upper case, the result will be the same.

How about integers?

string(variables('INT_TO_CONVERT'))
12

will return 

'12'

Exactly what we expect. Now let’s try with a negative value to see what happens:

string(variables('NEGATIVE_INT_TO_CONVERT'))
-12

will return 

'-12'

Let’s try the same for Float values:

string(variables('FLOAT_TO_CONVERT'))
12.3

will return 

'12.3'

string(variables('NEGATIVE_FLOAT_TO_CONVERT'))
-12.3

will return 

'-12.3'

So far, all of them are doing exactly what we expect them to do. First, let’s look at complex objects like arrays.

string(variables('ARRAY_TO_CONVERT'))
createArray('1','2','3')

will return

["1","2","3"]

Notice two important things. First, the values are separated with double-quotes and not single quotes because we’re using a JSON notation.

The second is the format. It looks exactly like a JSON array. You can use this function to quickly convert an array to a JSON to provide back to an API or another action.

Finally, let’s try to break it.

string(null)

will return

''

It’s an excellent detail from the development team because it doesn’t return an error. However, notice that other functions, like the substring function, will error if the parameters are null.

Limitations

Depending on the size of your string, 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 strings.

It’s a waste to do it on string variables since they are already strings. 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 string functions in a formula, you should review it and make everything more straightforward.

Sources:

Microsoft’s string Function Reference

Back to the Power Automate Function Reference.

Photo by Joe Calata 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 *