cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PJBruen
Resolver I
Resolver I

Using SET inside a FORALL Statement

Hi, 

 

I've seen various answers to this question, but I'm not able to work them out to suit my needs. I'm trying to create a Sharepoint folder structure from PowerApps. I'm calling a Power Automate flow to create the folder. The following code works fine:

 

ForAll(SharepointList1, ST_CreateFolder.Run(vYear, vTest, Title, "Dept1")); - so in this case, Title is derived from SharepointList1

 

What I would like to do however is loop through another Sharepoint list to derive the hard-coded value for "Dept1". What I was hoping was that I could do something like this.......but I now know this isn't possible.

 

ForAll(SharepointList2, Set(vDept, Title), ForAll(SharepointList1, ST_CreateFolder.Run(vYear, vTest, Title, vDept)));

 

Hopefully that makes sense. Is anyone able to guide me on this please?

 

Thanks, Paul

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@PowerRanger 

One thing to be aware of is that ForAll is not a traditional For Next loop as that would be more conducive to development...which PowerApps is not.

Also ForAll returns a table/collection.  So, it is quite easy to collect all the results of your Run results and then use that in another ForAll.

 

I'm not entirely clear on your intention with what you are trying to do, but some options are:

1) Lookup the value you want

   ForAll(SharepointList1, ST_CreateFolder.Run(vYear, vTest, Title, LookUp(SharePointList2, someCriteria, Title)))

2) Identify the Title as something else

   ForAll(SharepointList2 as list2, ForAll(SharepointList1, ST_CreateFolder.Run(vYear, vTest, Title, list2.Title)))

3) Combine the items in List2 into List1 and run against that

   ForAll(

        AddColumns(SharePointList1, "list2Items", Filter(SharePointList2, somecriteria)),  

            ForAll(list2Items, yourRunStatementHere)

   )

 

Some of the above may give you some guidance on where to go next.

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!

View solution in original post

3 REPLIES 3
PowerRanger
Resident Rockstar
Resident Rockstar

@PJBruen 

 

As you already figured ut you can't use Set withn a ForAll. You could use Collect instead to wright the results into a Collection.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.




​Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item.

If the content was useful in other ways, please consider giving it Thumbs Up.
RandyHayes
Super User
Super User

@PowerRanger 

One thing to be aware of is that ForAll is not a traditional For Next loop as that would be more conducive to development...which PowerApps is not.

Also ForAll returns a table/collection.  So, it is quite easy to collect all the results of your Run results and then use that in another ForAll.

 

I'm not entirely clear on your intention with what you are trying to do, but some options are:

1) Lookup the value you want

   ForAll(SharepointList1, ST_CreateFolder.Run(vYear, vTest, Title, LookUp(SharePointList2, someCriteria, Title)))

2) Identify the Title as something else

   ForAll(SharepointList2 as list2, ForAll(SharepointList1, ST_CreateFolder.Run(vYear, vTest, Title, list2.Title)))

3) Combine the items in List2 into List1 and run against that

   ForAll(

        AddColumns(SharePointList1, "list2Items", Filter(SharePointList2, somecriteria)),  

            ForAll(list2Items, yourRunStatementHere)

   )

 

Some of the above may give you some guidance on where to go next.

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!

Perfect - thanks.

 

Option 2 was the winner!

 

Regards,

Paul

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (1,796)