| 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.
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.
But as can be seen in the following code snippet, ForAll function limits the developer from saving data into a variable during iteration.
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.
But much to his disappointment, setting context variables is not allowed either.
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.
Yet again, no luck for the developer.
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.