Power Automate: Cloud Flows | Is the Array Empty?


The ask, suggest some alternative Power Automate logic for a group of non-dev cloud flow makers. Arrays and functions are new concepts to them, but they understand variables. So, instead of using the length() function to determine whether or not an array is empty, they would like some “more intuitive” logic for their Condition blocks:

Figure 1 - Power Automate cloud flow Condition block. Is the array length zero?
Figure 1Power Automate cloud flow Condition block. Is the array length zero?

Worth mentioning, they do understand that every cloud flow action returns its response as output. If the action title is singular like Create item or Add attachment, then the output body is a single data object. However, if the action title is plural like Get items or Get files (properties only), then the output body could be a list of data objects because more than one record can be returned:

Figure - 2- Power Automate cloud flow SharePoint action list.
Figure – 2Power Automate cloud flow SharePoint action list.

With that in mind, the suggestion here for a “more intuitive” approach is to initialize a flow variable (e.g., emptyArray) of type Array. Provide no default value as it will represent an array with no records and that is all the non-devs need to understand for now:

Figure 3 - Power Automate cloud flow Initialize variable action for empty array.
Figure 3Power Automate cloud flow Initialize variable action for empty array.

Now, instead of measuring the length() of a results array, compare the resultsArray variable to the emptyArray variable. If the two variables aren’t equal, then the resultArray isn’t empty:

Figure 4 - Power Automate cloud flow Condition block. Is the array result equal to an empty array?
Figure 4Power Automate cloud flow Condition block. Is the array result equal to an empty array?

Conclusion:
The TRUE/FALSE logic of the Condition block will execute correctly using either approach. This simply shows the flexibility of Power Automate as makers can build the same flows slightly differently. If a maker prefers to use functions in their logic, then that’s perfectly fine. However, if a maker doesn’t understand functions and would prefer not to use them, then there are still ways to achieve the same result.

“My race needs no special defense, for the past history of them in this country proves them to be equal of any people anywhere. All they need is an equal chance in the battle of life.”

Robert Smalls

#BlackLivesMatter

Leave a comment