November 6, 2024

The length function is handy to get the size of a string or the number of objects of a collection. So you can use it both with String and Arrays.

Usage

It follows a simple pattern.

  1. String or Array

I will return a number.

Example:

Let’s start with a simple example:

createArray('Manuel','T.','Gomes')

will return 

15

Let’s try it with an array. To do that, we’ll use the “createArray” function. It’s super useful to create an array of objects.

length(createArray('Manuel','T.','Gomes'))

will return 

3

Limitations

I could not find a hard limitation for this function. I’ve passed strings with 30000 characters and huge arrays, and it returned almost instantly. But keep in mind that an undocumented limit may exist, so keep your strings and arrays as short as possible.

Please be careful with the values that you’ll pass in the function. If you have a numeric variable, the Flow will be validated as correct, but it will fail when you run it.

Recommendations:

  1. Keep the parameters in variables. Don’t pass them directly in the formula. You can do that, but it will make your formula quite prone to error. For example, if you want to check the string “Manuel ’T. Gomes’” (Notice the quotes), the function will return an error because it will consider the quotes as the string’s end. Having data on separate variables helps a lot in avoiding these issues.
  2. Don’t create the arrays inside the length. Please keep them in a separate variable. The example above is to demonstrate and keep it short, but don’t do it. This may result in issues, and it’s harder to debug.
  3. Don’t nest it. There’s no real reason to do it, but if you find yourself in a situation where you have nested length functions in a formula, you should review it because you’re probably doing something wrong.
  4. Please note that formulas may have localization-based differences. For example, you should write “join” with “separating each of the arguments, but if your regional settings are set to Portugal, you should use “;” instead.

Sources:

Microsoft’s length Function Reference

Back to the Power Automate Function Reference.

Photo by patricia serna 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