cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
romankorchak2
Helper II
Helper II

Monitoring Forall loop

Hi All

I am just wandering if there are any way to monitor at which stage Forall loop is
So if I am updating 2000 SP list items - can I have a label which would show how many items already updated etc?

Shame we cannot updatecontext from within forall 🙄 
Thanks

2 REPLIES 2
romankorchak2
Helper II
Helper II

I think I found it - you can create 2 collections and collect new item into first one every time and collect to second one every time Forall passes certain amount of items. 
So something like

Clear(C1);  Clear(C1); 
ForAll(Filter(MySPlist,Country <> "GB") As it, 
  Collect(C1, {i:1}); 
  If(Mod(CountRows(C1),100) = 0 , Collect(C2,{i:1}) );
  Patch(MySPlist, LookUp(MySPlist, ID=it.ID),{Country:"GB"} ) 
) 


  

RandyHayes
Super User
Super User

@romankorchak2 

The reason you cannot use UpdateContext and other actions in a ForAll is that ForAll is a function that creates a table.  It is not a For Loop like in some development platform.  

When you use the ForAll backward like you have, it will still attempt to function, but your performance will be quite horrible as you are invoking the Patch function on a datasource over and over and then performing a lookup in it as well.  All will work, but the performance will be poor.

 

Your formula should have been this for better performance and to utilize the ForAll properly:

Patch(MySPlist, 
    ForAll(Filter(MySPlist,Country <> "GB") As it, 
        {ID: it.ID,
         Country:"GB"
        } 
    ) 
) 

This formula produces a Table (which is what ForAll is for) and passes that to the Patch function which will then intelligently update all the records from the table provided to the datasource.

 

However...you might also want to consider not doing any of this and simply using the UpdateIf function.  Then your formula will be:

UpdateIf(MySPlist, Country <> "GB", {Country:"GB"}) 

 

Keep in mind that all of the formula (including the formula in your last post) are all limited by the record limit of your app.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (6,100)