Skip to main content

Notifications

Community site session details

Community site session details

Session Id : sXWhvEKp6azDgmwjTdimDU
Power Apps - Building Power Apps
Answered

Getting data from collection row in forall

Like (1) ShareShare
ReportReport
Posted on 15 Aug 2023 22:25:42 by 260

I need some help solving this and thank you all in advance.

 

I have a collection that is bulit from user actions which has several columns:

 

  • Image
  • Image Title
  • File Name
  • File Path

the first three are created each time a Collect() is done.  The FilePath gets created by running a Power Automate that is the returned value.  The problem I am trying to solve is how, inside a ForAll(), I can use each File name value to pass as a parameter to the Power Apps run. command.

 

Here's what I am trying to do:

 

ForAll(Sequence(CountRows(colItems)),
Patch(colItems, Index(colItems, ThisRecord.Value),
{FilePath: SignaturePhoto.Run(<colItems.FileName>).FilePath })
);

 

I tried using ThisRecord.FileName but it doesn't work.  So how do I specify the column value from the record in coItems being processed>  This proably will be so obvious once someone responds.

  • Verified answer
    lmheimendinger Profile Picture
    260 on 17 Aug 2023 at 17:30:50
    Re: Getting data from collection row in forall

    Here's what did work.

     

    When I did Collect() to add an item to the collection, I also did a Collect() to a duplicate collection.  When the collection is complete, I then do this:

     

    ForAll(colDuplicate,
    Patch(colItems, ThisRecord,
    {FilePath: "https://<stuff>" & <flowname>>.Run(varAction, ThisRecord.FileName,ThisRecord.,columnname>).varpath}
    )
    );

    The flow returns the file path when it saves the item into a SharePoint library.  colDuplicate is an exact copy of colItems so I use the ForAll on it but Patch the correspondind record in colItems. 

     

    I appreciate the helpful suggestions which got me to the right place.

     

     

     

  • lmheimendinger Profile Picture
    260 on 15 Aug 2023 at 23:54:02
    Re: Getting data from collection row in forall

    I forgot that I switched to Seququence() because you can't patch a record in the collection used by ForAll().

     

    Back to the drawing board.

  • lmheimendinger Profile Picture
    260 on 15 Aug 2023 at 23:24:33
    Re: Getting data from collection row in forall

    Going with the simplier solution but thank you.

  • lmheimendinger Profile Picture
    260 on 15 Aug 2023 at 23:23:56
    Re: Getting data from collection row in forall

    That appears to be workable as the expression works.  Thanks

  • poweractivate Profile Picture
    11,078 Most Valuable Professional on 15 Aug 2023 at 22:42:42
    Re: Getting data from collection row in forall

    @lmheimendinger 
    One more thing, for your scenario to work correctly, Power Apps should await for the Flow to complete.

    To make sure this happens, you must have at least one "Respond to a Power App or Flow" block in the Flow.
    poweractivate_4-1691771810432.png

    You also have to have one for there to be a return value to be used by FilePath in your Canvas App, and actually, also make sure to return an appropriate FilePath from the Flow for it to work correctly for your scenario.

  • poweractivate Profile Picture
    11,078 Most Valuable Professional on 15 Aug 2023 at 22:42:40
    Re: Getting data from collection row in forall

     

    @lmheimendinger 
    I don't recommend it (I recommend use my Patch outside ForAll way with the Collections instead), but if you really want to keep your original formula Patch inside ForAll, you may need to disambiguate ThisRecord like the following:

     

    With({wColItems: colItems},
     ForAll(wColItems,
     Patch(colItems, wColItems[@ThisRecord],
     {FilePath: SignaturePhoto.Run(ThisRecord.FileName).FilePath})
     )
    );
    

     

  • poweractivate Profile Picture
    11,078 Most Valuable Professional on 15 Aug 2023 at 22:40:08
    Re: Getting data from collection row in forall

    @lmheimendinger 

    Furthermore we should use Patch outside ForAll for better performing and easier to maintain formula, here's how:

     

    To reduce the overhead of patching inside a ForAll loop and instead collect the changes and patch them all at once, this can be achieved as follows:

    Step 1: Create Collections for Base Records and Changes

    First, you should create two collections, one for the base records and another for the changes. You can use the ForAll function along with ClearCollect for this purpose.

    For the base records:

    ClearCollect(colBaseRecs, colItems);
    

    For the changes:

    ClearCollect(colChangeRecs,
     ForAll(colItems,
     {
     ID: ThisRecord.ID,
     FilePath: SignaturePhoto.Run(ThisRecord.FileName).FilePath
     })
    );
    

    Step 2: Use the Patch Function with Collections

    Next, you can use the three-argument version of Patch to apply the changes. This version takes the data source (in this case, your original collection), base records, and changes as arguments:

    Patch(colItems, colBaseRecs, colChangeRecs);

    See if this helps as well @lmheimendinger 

  • Verified answer
    poweractivate Profile Picture
    11,078 Most Valuable Professional on 15 Aug 2023 at 22:35:58
    Re: Getting data from collection row in forall

    Not sure why you use ForAll on Sequence?
    Try like this:

    ForAll(colItems,
     Patch(colItems, ThisRecord,
     {FilePath: SignaturePhoto.Run(ThisRecord.FileName).FilePath})
    );
    

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 89 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 60

#3
stampcoin Profile Picture

stampcoin 48

Overall leaderboard