cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Apply to Each and terminate

Hi,

 

I have a Flow that gets triggered when a SalesForce record is modified and then updates the same record in a SharePoint list.

The Flow works by getting all the list items (SharePoint - Get Items) and matching the list record number with the record number of the modified SalesForce record. The flow works fine but takes 1h to run.

 

I have 7000 unique items in the SharePoint list and I would like the flow to stop after it has found the one item that needs to updated. Right now I have initialized a variable to 0 which gets set to 1 when the list item is updated - when the variable is 0 the flow stops doing anything but it still has to go through the rest of the list items. I tried putting the Apply to Each inside a Do Until but it didn't work: the do until only "looped through" one instance since the Get Items returns one instance - or so it seemed.

 

Is there any way to terminate the Flow inside the Apply to Each... control terminate isn't allowed inside an Apply to Each 😞

 

Heres a picture of the flow:

flow.PNG

 

 

 

 

 

 

Regards,

T

7 REPLIES 7
vecerpa
Memorable Member
Memorable Member

Hi @Anonymous,

 

Right now there is no simple way to exit apply to each.

There is already added Idea in Flow forum, so please vote for it - https://powerusers.microsoft.com/t5/Flow-Ideas/Exit-from-quot-Apply-to-Each-quot/idi-p/30760#M1733.

 

But I was just thinking how to better update SharePoint list item and not to go throught whole list. I know that each item have specific ID generated by SharePoint. So my ID is to somwhere inside salesforce, possible programatically, store such ID for furhter usage inside SharePoint list. You will have easier way and of course faster to update ShP list. It can be somewhere in comments of such item.

P.

 

Anonymous
Not applicable

Hi @vecerpa,

 

Yes, SharePoint generates a unique ID as well, the problem is I don't know which item has what ID, thats why I can't use Get Item instead of Get Items. In addtion, I have no way of matching any salesForce field to my Sharepoint ID.

 

To get rid of the unnecessary looping of 7k items, I tried adding a filter query to my Get Items ( Number eq 'Opportunity Number') but I get an error that column Number doesn't exist...

 

Regards,

T

ScottShearer
Super User
Super User

@Anonymous- You mention in your post that you have 7000 ittems that you want to loop through with a for each loop.  You should be aware that the Flow documentation indicates that there is a hard limit of 5000 iterations for a for each loop.

 

Scott

 

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
Anonymous
Not applicable

Hi @ScottShearer,

 

My flow loops through them - I'd prefer that it didn't. I'd want it to loop until it finds a match or then filter Get Items before it loops.

 

Heres an example of a succesful flow:

It seems that it does loop through 7k items...

applytoeach.PNG

 

 

 

 

 

 

 

 

 

 

Regards,

T

@AnonymousVery interesting...

 

I just tried to configure Get Items to retrieve over 5000 items in order to run a test of Apply to Each, but I got an error when I tried to save the Flow saying that I can't set it above 5K.  I know that I was able to do so within the past few days.   If I don't turn on pagination, it will save for me but it reverts back to 100 item max.

 

I wonder if changes are being made to this functionality that are slowly being rolled out.

 

MaxCount.jpg

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
Anonymous
Not applicable

@ScottShearer

 

Interesting indeed..I agree, this might be because of changes in the functionality.

 

My flow has been active for the last 4 days and I haven't had an error with the item amount.

My pagination is on and I've set the limit to 15000:

 

pagination.PNG

 

 

 

 

 

 

 

One thing that might somehow have an effect is the fact that my coworker originally created the flow until the get items part and he set the limit to 15k.

I also tried creating my own new flow and I'm still able to set the limit to 15K.

 

The 5K limit is applied to CDS, not necessarily to other data sources. Excel, for example, has a limit of 250 rows when you read it from OneDrive...

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

PA Survey Carousel Image.png

We want to hear from you!

If you are a small business ISV/Reseller, share your thoughts with our research team.

Users online (1,931)