web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / get IDs of patched rec...
Power Apps
Answered

get IDs of patched records inside ForAll

(1) ShareShare
ReportReport
Posted on by 304

Hi everyone,

in my app I have a patch function inside a ForAll loop. This function patches records from a collection to a sharepoint list, which works pretty well so far.

My problem now is, I need the IDs of the newly created records from that sp list, to pass them to a flow. How could I achieve that?

I already read about saving the IDs inside a variable, but I'm not sure, if that would work inside the loop?

Categories:
I have the same question (0)
  • Daniel Bocklandt Profile Picture
    5,151 Super User 2026 Season 1 on at

    Hey @LisKr ,

     

    The variable will not work, since you can't change variables in a ForAll loop but you can use a collection. here an example of how you could do that: 

    Clear(colID);
    ForAll(Collection, Collect(colID,Patch(SharepointList,Defaults(SharePointList),{...})))

     

    This way you get every column from the Sharepoint List of the records created. 

    Let me know if it helped you.

     

  • LisKr Profile Picture
    304 on at

    Hi @DBO_DV ,

    thank you, that seems to work! Only one question: how can I access the ID to pass it to the flow? Is it colName.ID? If yes, I somehow get an error.

  • Daniel Bocklandt Profile Picture
    5,151 Super User 2026 Season 1 on at

    Hey @LisKr ,

     

    I don't know this by heart. but you can find it fairly easily in Power apps 

    DBO_DV_0-1719824885263.png

    There you can see all the columns that are returned, and also find the ID column. 

     

  • LisKr Profile Picture
    304 on at

    Hi @DBO_DV ,

    I see. However, I still have two problems.

    • Firstly, how to reference the ID column in my code? I tried using "colRecords.ID" but I get an error stating that it expects text, but gets a table. How can I convert it into text? I haven't found a working solution yet. 
    • And secondly, if there are more than one elements in the collection, I need to pass the IDs separately to different runs of a flow and I've no idea how to do so. Do you know what I mean?

     

    Maybe it helps if I explain the use case. That is the following: I have multiple galleries on my screen, each linked to different sharepoint lists. Now I'm building a solution to copy elements from one gallery/list to another. I've done that with saving the selected elements to a collection (colCopy) and then, with a ForAll loop and a patch function, creating the records in the new list.

    What I need to achieve now, is to also copy the associated files (stored in a library) to a new library. I tried approaching that with triggering a flow run for each patch, but for that, I need to be able to pass only one ID at a time. I hope it's somehow understandable.

    My current code looks like that (colCopy = elements to copy, colRecords = the collection containing the patched items):

     

    Clear(colRecords);;
     ForAll(
     colCopy;
     Collect(
     colRecords;
     Patch(
     InstructionsMachine;
     Defaults(InstructionsMachine);
     {
     Otsikko: ThisRecord.Title;
     Text: ThisRecord.Text;
     Attachments: ThisRecord.HasAttachment;
     Machine: CopyDropdownKone.Selected.Machine
     }
     )
     );;
     'TEST-GradeProduct:CopyAttachments'.Run(
     ID4.Text;
     "AttachmentsMachine";
     colRecords.ID
     )
     )

     

     

  • Daniel Bocklandt Profile Picture
    5,151 Super User 2026 Season 1 on at

    Okay I get it. 

    The error Tells you that there are several columns inside of your one ID column (nested columns). if you need only the id you could try something like this:

    Clear(colRecords);;
     ForAll(
     colCopy;
     Collect(
     colRecords;
     Patch(
     InstructionsMachine;
     Defaults(InstructionsMachine);
     {
     Otsikko: ThisRecord.Title;
     Text: ThisRecord.Text;
     Attachments: ThisRecord.HasAttachment;
     Machine: CopyDropdownKone.Selected.Machine
     }
     ).ID
     ));;
     

     

    For your problem with the flow: you could start another forAll loop with colRecords or you pass a one columned table to your flow as JSON and then you create inside of Power Automate the loop. That would be way more efficient then looping through it inside of Power apps. 

     

    Could you check what you get from the new code?

     

  • LisKr Profile Picture
    304 on at

    Now I only get the ID, thanks!

     

    Could you please explain more on what you mean with that and how to do? I sadly don't really understand:

     


    or you pass a one columned table to your flow as JSON and then you create inside of Power Automate the loop

     


    Would it maybe help if I post a screenshot from may flow, how it is right now?

  • royg Profile Picture
    on at

    Hi @DBO_DV,

    I think what @LisKr meant is that it's less efficient to iterate  the items and invoke the flow for each of the IDs.

    Instead Join them together as a table using JSON function or even concatenate them into a comma delimited string (example: Concat(colRecords, ID,",")) and pass that to your flow which in turn will parse/split the input back into a table and iterate the IDs to perform your logics.

  • LisKr Profile Picture
    304 on at

    Hi @royg , @DBO_DV 

    how exactly should I handle the table in the flow? I guess I choose "user input text" in the trigger and pass it as usual? But how do I proceed after that? Like what actions do I need and how do I achieve it, so that each of the IDs is treated separately? 

     

    Right now my flow is like this:

    1. I pass the old ID, the new ID and the library to the flow as text input

    2. I initialize a variable with the old folder path

    4. I use list folder action to list all folders under that path 

    3. with a condition, I check if there is a folder (with length function)

    4. if yes, I copy that folder to the new destination (passed from the app)

    In previous testing, it seems that the list folder action raises an error, if there's no folder found. So I will need to find another way for that, too

  • royg Profile Picture
    on at

    Again, 2 options: if you pass a collection (that you stringify using the JSON function, then, in your flow you use a ParseJSON to convert the input text back into an array. The other option is to pass in the pairs of IDs concatenated into a single string, something like: 1:1,2:2,3:4,... In your flow split the list by comma to get an array of pairs (x:y) which you can iterate and split by : to get new/old ids.

    Regardless of your selected option, you need to iterate pairs of IDs and perform the list of actions you mentioned above.

     

  • LisKr Profile Picture
    304 on at

    That does help me with understanding, thanks. So I definitely need to put both IDs, old and new, into one collection, correct? Right now there's only the new ones in it

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 427 Most Valuable Professional

#2
11manish Profile Picture

11manish 201 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard