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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / ForAll Patching the ID...
Power Apps
Unanswered

ForAll Patching the ID from previous list item to another Entity

(0) ShareShare
ReportReport
Posted on by 253

Hello,

 

I have a main entity (Products) and a child entity (Tasks). What I need to happen is when I create a new item within the Products lists, my Power App creates a collection from static data sitting in SP and creates new records in my Tasks entity. This then gives the record in the Product entity and all of the ones created in the Tasks entity matching ID's (the auto-generated ID from the Products entity is patched to a Text field in the Tasks entity.

 

I have got most of this working by creating a collection and then doing a ForAll patch, however the problem is because I am submitting the Products list and trying to create new Tasks at the same time, it isn't always grabbing the ID properly. I have tried putting the data into an 8 second timer but even still this is missing some of the ID's. The other issue with doing this is it has to hold onto a loading screen for 8 seconds which isn't a great customer journey.

 

What is the best way to either:

 

a) grab the ID from the most recent record but make sure the record has hit the source or;

b) use the relationships on CDS to somehow recognise it is the same case

 

Thanks

I have the same question (0)
  • PaulD1 Profile Picture
    2,914 on at

    Patch can return the value of the submitted record - e.g.

    Set(varNewID,Patch('MyTable',Defaults('MyTable'),{Field1: Value1, Field: Value2}).ID

    So you want to grab the ID returned from the Patch and use that...

    Unfortunately you are not allowed to use a Set statement or an UpdateContext inside a ForAll loop. You can however use a collection - something like this:

    ClearCollect(colID, {NewID: Blank()});
    ForAll(....,
    Patch(colID,First(colID),{NewID:
    Patch('MyTable',Defaults('MyTable'),{Field1:Value1, Field2: Value2}).ID;
    Patch('MyChildTable',Defaults('MyChildTable'),{ID: First(colID).ID, Field1: Value1, Fied2: Value2})... 
    

    So you are setting up the collection (colID) initially with a single blank record/value for the ID. As you perform the ForAll, when the Patch to 'MyTable' is performed, the ID of the new record is put into the colID record. You can then use this ID when patching to 'MyChildTable'.

    The Patch to 'MyChildTable' may be in its own ForAll loop.

    Hope that helps

  • sammybridge Profile Picture
    253 on at
    Thanks for all the replies. I just took the long way round and instead of setting variables I just used the variable code repeatedly throughout my code and this has worked.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 802 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 332 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 273

Last 30 days Overall leaderboard