Canvas Apps - Is “For All” really a For loop?

| Mohsin Ahmed

How many times have you run into a scenario where you had a collection to work with and all you wanted to do was to iterate through the collection and take some actions on each element? I’m sure I have run into such a scenario quite a few times.

Canvas Apps’ function library has us covered. It provides a function called “ForAll” particularly for this scenario. This function enables us to iteratively perform actions on the collection.

But is this function viable to be used for large collections and/or complex iterative actions? Upon close inspection, we can deduce that the present implementation of the ForAll function is indeed limited.

Consider this simple collection of Planets.

Power App forAll limitations

The developer of this application wants to perform some actions on this collection. Let us see how ForAll function fares in this scenario. Since we’re talking about planets here, it is imperative that the developer must carry out complex calculations and logic in order to get the current coordinates of the planets.

Some of these complex calculations might involve saving some information from each iteration of the collection as variables for future use.

Power App forAll limitations Issue 1

But as can be seen in the following code snippet, ForAll function limits the developer from saving data into a variable during iteration.

Power App forAll limitations Issue 2

Then the developer might want to fall back to using good old context variables to save some information along his journey through the Solar System collection.

Power App forAll limitations Issue 3

But much to his disappointment, setting context variables is not allowed either.

Power App forAll limitations Issue 4

Furthermore, the developer might want to update some information received from the international space station, back into the planet collection. Albeit updating a collection when looping through it is a bit reckless, but the developer here is working with planets, they must be confident in what they’re doing.

Power App forAll limitations Issue 5

Yet again, no luck for the developer.

Power App forAll limitations Issue 6

Hence, it seems logical to conclude that the present implementation of the ForAll function in Canvas Apps is indeed a bit limiting for developers. Especially for those developers who are accustomed with conventional programming and want finer control over what they want to achieve and how they want to achieve it with Canvas Apps.

But all is not lost yet. There are workarounds to counter these shortcomings. Join us in the next blog of this series where we will deep-dive into the Timer control available in Canvas Apps and how that can be used as an alternative to the ForAll function for achieving conventional For loop like functionality.

Learn more about Imperium's Power App Services. We hope this information was useful, and we look forward to sharing more insights into the Power Platform world.


M
Chief Architect, Founder, and CEO - a Microsoft recognized Power Platform solution architect.

About The Blog

Stay updated with what is happening in the Microsoft Business Applications world and initiatives Imperium is taking to ease digital transformation for customers.


More About Us

We provide guidance and strategic oversight to C-Suite and IT Directors for on-going implementations. Feel free to give us a call.

1 331 250 27 17
Send A Message

Ready to Start?

Get a personalized consultation for your project.

Book a Meeting