Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Duplicates created in the target list for bulk updates using patch and forall

(1) ShareShare
ReportReport
Posted on by 12
Hi Everyone,
 
I am new to Power Apps, so please excuse me if this question has already been answered.

I have a source list where each record has certain columns, such as City and State, with predefined dropdown values. Once can update multiple rows at the same time, and ID is the unique identifier for each record. I have created a checkbox and am trying to perform a bulk update using a button.

These updates are then created in a target list. First, it needs to check if there is an existing record  for that source ID in the Title Column. If yes, it updates the existing record; if not, it creates a new record. The ID is the unique identifier in the target list. The logic works as expected for a single update. However, when performing a bulk operation (e.g., selecting three rows from the app), it creates 3 new rows in the target for the source record maximum ID(all 3 rows are not available in the target), and the other two rows are completely ignored.

Source List

ID Customer ID City State
12 ABC123 Buffalo NY
13 XYZ456 Orlando FL
 
 
Target List
 
ID Title Customer ID City State
01 13 XYZ456 Orlando FL
02 14 XYZ456 Orlando FL
 
 
ForAll(
    SelectedRecords,

    Notify("Processing record with Source ID: " & Text(ThisRecord.ID), NotificationType.Information);

    // Check if a record with the Title (mapped from Source ID) exists
    If(
        !IsBlank(LookUp(Target_List, Title = Text(ThisRecord.ID))), // Check existence
        // Update existing record if found
        Notify("Updating existing record with Source ID: " & Text(ThisRecord.ID), NotificationType.Information);
        Patch(
            Target_List,
            LookUp(Target_List, Title = Text(ThisRecord.ID)), // Find the existing record by Title
            {
                'Updated State': UpdatedState.Selected,
                'Updated City': UpdatedCity.Selected,
                'CUSTOMER ID': CustID.Text
            }
        ),
        // Create a new record if not found
Notify("Creating new record with Source ID: " & Text(ThisRecord.ID), NotificationType.Information);
		Patch(
            Target_List,
            Defaults(Target_List), // Create a new record
            {
                Title: Text(ThisRecord.ID),  // Map Source ID to Target Title
                'Updated State': UpdatedState.Selected,
                'Updated City': UpdatedCity.Selected,
                'CUSTOMER ID': CustID.Text
            }
        )
    );

    // Notify the end of processing for each record
    Notify("Finished processing record with Source ID: " & Text(ThisRecord.ID), NotificationType.Success, 3000);
);
 
  • LB-08081540-0 Profile Picture
    12 on at
    Duplicates created in the target list for bulk updates using patch and forall
    Thanks for your response, this works as expected
  • Verified answer
    WarrenBelz Profile Picture
    146,660 Most Valuable Professional on at
    Duplicates created in the target list for bulk updates using patch and forall
    There are a few issues here that I will try and set out.
    • Firstly Notify functions inside a ForAll() statement are not a good idea, so I have removed them for the purpose of simplifying this.
    • The fundamental issue however is that you are referring to controls in the patch, but using (I assume) a collection in the ForAll(). You need to use the filtered Gallery if you are going to refer to control values.
    • Also I have simplified the new/update logic by finding the ID (I assume you are using SharePoint) of the target record. If it is present, the code will update that record. If not, it will create a new record.

    Notify(
       "Processing record,
       NotificationType.Information
    );
    ForAll(
       Filter(
          GalleryName.AllItems,
          YourCheckBox.Value
       ) As _Data,
       With(
          {
             _ID:
             LookUp(
                Target_List, 
                Title = Text(_Data.ID)
             ).ID
          },
          Patch(
             Target_List,
             {
                ID:_ID,
                'Updated State': _Data.UpdatedState.Selected,
                'Updated City': _Data.UpdatedCity.Selected,
                'CUSTOMER ID': _Data.CustID.Text
             }
          )
       )
    );
    Notify(
       "Finished processing record, 
       NotificationType.Success, 
    ​​​​​​​ 3000 );
     
    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 u
    seful in other ways, please consider giving it Thumbs Up.
    MVP (Business Applications)   Visit my blog Practical Power Apps

     

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,660 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard