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.
It follows a simple pattern.
- String or Array
I will return a number.
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
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.
- 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.
- 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.
- 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.
- 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.
Microsoft’s length Function Reference
Back to the Power Automate Function Reference.
Photo by patricia serna on Unsplash