cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Fulljames
Frequent Visitor

Looping over Collection records

Hi,
I'm currently stuck trying to loop over records stored in a collection.

My aim is to call my Power Automate flow for each row.

My collection consists of five columns (Event Name, Name, Start Date, End Date, Telephone) and I need to loop for each row, inside the loop I need to call my Power Automate flow.
I have managed this with a singular record using the ForAll function which loops the correct amount of times but only uses the most recent row in the collection when it calls the Power Automate flow, causing duplication.  

Any help with this would be much appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@Fulljames 

Okay...so if you are collecting EventName_txt for example, in your collection (which is a control...not a value) for the EventName column, then you need to reference that in your formula.

That is why you are getting the screen values and not what is in the collection...because you are not referencing the value in the collection.

 

So, first, your collect statement line in the formula you have should be this:

Collect(FormResponses1, 
    {EventName: EventName_txt.Text, 
     StartDate: StartDate_pkr.Text, 
     EndDate: EndDate_pkr.Text, 
     Name: Name_txt.Text, 
     TelephoneNumber: Tel_txt.Text
    }
); 

 

And your looping formula this:

If(Connection.Connected, 
    ForAll(FormResponses1,
        OfflineEventDoc.Run(Email_txt.Text, Name_txt.Text,
        "<!DOCTYPE html>
         <html>
            <head>
               <title>Event Doc</title>
            </head>
            <body>
            <p>
            Event Name: " & EventName & "<br><br>

            Start Date: " & Text(StartDate, ShortDate) & "<br><br>
            End Date: " & Text(EndDate, ShortDate) &"<br><br>

            Name: "& Name &"<br><br>
            Telephone Number: "& TelephoneNumber &"<br><br>

            </p>
            </body>
         </html>
      ")
  )
)
_____________________________________________________________________________________
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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

View solution in original post

6 REPLIES 6
Bilakanti
Responsive Resident
Responsive Resident

@Fulljames ,

 

I have replicated your requirement and it's working fine for me. I have on collection with 5 records and I executed flow for each record and flow ran successfully 5 times with 5 different outputs.
Screenshots below.

Bilakanti_0-1615895232880.pngBilakanti_1-1615895249955.pngBilakanti_2-1615895272869.png

 

RandyHayes
Super User III
Super User III

@Fulljames 

What is the formula you are using?  If you say that you are only getting the most recent row in the collection, then you are referencing your collection improperly.  Is there a particular need for a collection?  Is this coming from a Gallery or other source?

_____________________________________________________________________________________
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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

Hi @RandyHayes ,
The data is being entered into a collection via date pickers and textboxes.
I've been referencing my collection like so:

ForAll(FormResponses1,
If(Connection.Connected, OfflineEventDoc.Run(Email_txt.Text, Name_txt.Text,"<!DOCTYPE html>
<html>
<head>
<title>Event Doc</title>
</head>
<body>
<p>

Event Name: "& EventName_txt.Text &"<br><br>

Start Date: "& StartDate_pkr. &"<br><br>
End Date: "& EndDate_pkr. &"<br><br>

Name: "& Name_txt.Text &"<br><br>
Telephone Number: "& Tel_txt.Text &"<br><br>

</p>
</body>
</html>
")))
RandyHayes
Super User III
Super User III

@Fulljames 

How and what are you putting into this collection?

You are referencing controls in your formula (i.e. Email_txt.Text, Tel_txt.Text, etc.) These are going to reference the controls in your app...nothing from your collection.

_____________________________________________________________________________________
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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

@RandyHayes 
I load data into the collection on an OnClick function like so:

If( Connection.Connected, PUREMcLarenEventWaiver.Run(Email_txt.Text, PrintName_txt.Text,"<!DOCTYPE html>
<html>
<head>
<title>Event Doc</title>
</head>
<body>
<p>
Event Name: "& EventName_txt.Text &"<br><br>
Start Date: "& StartDate_pkr. &"<br><br>
End Date: "& EndDate_pkr. &"<br><br>
Name: "& Name_txt.Text &"<br><br>
Telephone Number: "& Tel_txt.Text &"<br><br>
</p>
</body>
</html>
"), 
Collect(FormResponses1, {EventName: EventName_txt, StartDate: StartDate_pkr, EndDate: EndDate_pkr, Name: Name_txt, TelephoneNumber: Tel_txt}); 
SaveData(FormResponses1, "LocalSavedItems1"));

  

How would I go about correctly referencing the items within the collection?

RandyHayes
Super User III
Super User III

@Fulljames 

Okay...so if you are collecting EventName_txt for example, in your collection (which is a control...not a value) for the EventName column, then you need to reference that in your formula.

That is why you are getting the screen values and not what is in the collection...because you are not referencing the value in the collection.

 

So, first, your collect statement line in the formula you have should be this:

Collect(FormResponses1, 
    {EventName: EventName_txt.Text, 
     StartDate: StartDate_pkr.Text, 
     EndDate: EndDate_pkr.Text, 
     Name: Name_txt.Text, 
     TelephoneNumber: Tel_txt.Text
    }
); 

 

And your looping formula this:

If(Connection.Connected, 
    ForAll(FormResponses1,
        OfflineEventDoc.Run(Email_txt.Text, Name_txt.Text,
        "<!DOCTYPE html>
         <html>
            <head>
               <title>Event Doc</title>
            </head>
            <body>
            <p>
            Event Name: " & EventName & "<br><br>

            Start Date: " & Text(StartDate, ShortDate) & "<br><br>
            End Date: " & Text(EndDate, ShortDate) &"<br><br>

            Name: "& Name &"<br><br>
            Telephone Number: "& TelephoneNumber &"<br><br>

            </p>
            </body>
         </html>
      ")
  )
)
_____________________________________________________________________________________
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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,186)