Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Suggested answer

Patch ForAll with feedback of IDs and second Patch

(1) ShareShare
ReportReport
Posted on by 35
Hi guys, I'm hoping someone can help me out with the most efficient way of doing this.
 
I am trying to create a mechanism where records are linked to a previous record using another column that references the ID of the row it is linked to in a SharePoint List.
 
I currently have a gallery with combo boxes and text inputs that are patched to the SharePoint list using a ForAll and Patch as below.  The ID's in the gallery are purely for the user to be able to link them using the "Follow From" column.  When patched, the IDs will be the automatically created IDs in SharePoint.
 
When the records are patched to SharePoint, I there need to get the ID that are created and use them in place of the Follow From options, something like this:
 
Gallery that users populate:
ID Follow From
1  
2 1
3 1
 
SharePoint List:
ID Previous ID
14  
15 14
16 14
 
I'm guessing this will need to be 2 patches with a return of the IDs in between, but I'm hoping someone can help me out with the best way of doing it. 
 
1. Patch records to SharePoint whilst returning IDs
2. Translate Follow From IDs to actual SharePoint IDs
3. Patch Previous ID to SharePoint list
 
 
Here how far I've got:
 

Input Gallery:

 

Initial Patch Command:

Set(LastPatch,
    ForAll(Gallery1.AllItems,
        
        Patch('Design Activities',Defaults('Design Activities'),
            {
                Title: TextInputCanvas3_2.Value,
                Category: ComboboxCanvas6.Selected,
                Status: ComboboxCanvas6_3.Selected,
                Designer: ComboboxCanvas6_1.Selected,
                link_op: globalCurrentOP.ID
            }        
        )
            
    ).ID
); 

I've managed to get the newly created ID's by surrounding the ForAll with a Set command as above, but I'm struggling with where to get go next.
 
Categories:
  • Suggested answer
    WarrenBelz Profile Picture
    148,353 Most Valuable Professional on at
    Patch ForAll with feedback of IDs and second Patch
    This should give you a Table Variable LastPatch containing the ID column and the IDs of all the records you have just created from the Gallery. I have to assume here that Category, Status and  Designer are Choice columns.
    Set(
       LastPatch,       
       Patch(
          'Design Activities',
          Defaults('Design Activities'),
          ForAll(
             Gallery1.AllItems As _Items,
             {
                 Title: _Items.TextInputCanvas3_2.Value,
                 Category: _Items.ComboboxCanvas6.Selected,
                 Status: _Items.ComboboxCanvas6_3.Selected,
                 Designer: _Items.ComboboxCanvas6_1.Selected,
                 link_op: globalCurrentOP.ID
             }        
          )
       ).ID
    ); 
     
    Please click Does this answer your question 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 a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee
  • Suggested answer
    Ytalo Silva Profile Picture
    127 on at
    Patch ForAll with feedback of IDs and second Patch

    Hello @dbarnesab, when I need to link one item to another before having its ID, I use a GUID.

    One possible approach is to create a new collection with a custom GUID for each item:

    When initializing your collection (or on screen load), generate a GUID per row.

    ClearCollect(
    colRecords,
    AddColumns(YourOriginalSource, "CustomGUID", Text(GUID()))
    )
    Then use Patch to create those items in SharePoint with their respective GUIDs:
    ForAll(
        colRecords,
        Patch(
            SharePointList,
            Defaults(SharePointList),
            {
                Title: ThisRecord.Title,
                CustomGUID: ThisRecord.CustomGUID,
                FollowFromGUID: ThisRecord.FollowFromGUID,
                // any other fields...
            }
        )
    );
    Note: FollowFromGUID is selected via a ComboBox in the gallery, where users can choose another item by name and bind the selected item’s GUID.
     
    If you also want to get the FollowFromID, you can use:
     
    ForAll(
        colRecords,
        Patch(
            SharePointList,
            LookUp(SharePointList, CustomGUID = ThisRecord.CustomGUID),
            {
                FollowFromID: LookUp(
                    SharePointList,
                    CustomGUID = ThisRecord.FollowFromGUID,
                    ID
                )
            }
        )
    )
    I hope this helps or at least gives you a good starting point! 😊 Let me know if you’d like help adapting this to your exact use case.

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 1