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 / Duplicate records gett...
Power Apps
Unanswered

Duplicate records getting created on click on Copy Button

(0) ShareShare
ReportReport
Posted on by 652
Hello,
 
Within my gallery I've added a check box to create a duplicate records of the selected item. I can select multiple checkbox to create a new record of the selected checkboxes.
 
But when I click the copy button it is creating 2 duplicates of the selected record (checkbox) and 2 blank records.
 
For instance If I'm selecting 1 check box and click copy, it should only create/copy 1 record. If 23 checkboxes are selected, it should create/copy 3 new records.
 
Below is the formula used OnSelect of a button:
Set(
    varNumber,
    varNumber + 1
);
ForAll(colSelectd,
Collect(colGridData, varNewRecord,
        Patch( varNewRecord, {
            ID: varNumber,
            Agent Name: ThisRecord.Business,
            'Customer Name': ThisRecord.'Analyst Name',
            'Resource Name': ThisRecord.'Supplier Name',
            'Date': ThisRecord.'Supplier Name in SI',
            Comments: ThisRecord.Comments

        }
        )
    )
    ); Clear(colSelectd); Reset(CheckboxAll);
Please advise on how to fix this. Thanks!
Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    153,721 Most Valuable Professional on at
    A little unsure exactly what you are trying to do here with the Variable in the middle, but if you are trying to collect all records from colSelectd into colGridData with the field name changes and a sequential ID.
    With(
       {
          _List:
          ForAll(
             colSelectd As _Data,
             {
                'Agent Name': _Data.Business,
                'Customer Name': _Data.'Analyst Name',
                'Resource Name': _Data.'Supplier Name',
                'Date': _Data.'Supplier Name in SI',
                Comments: _Data.Comments
             }
          )
       },
       ClearCollect(
          colGridData,
          ForAll(
             Sequence(CountRows(_List)),
             Patch(
                Index(
                   _List,
                   Value
                ),
                {ID: Value}
             )
          )
       )
    );
     
    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    Buy me a coffee
  • Prem4253 Profile Picture
    652 on at
    @WarrenBelz,
     
    Below is the screen shot of the app:
     
     
     
    For instance If we select the first 2 checkbox and click Copy, so 2 new records should get copied.
     
    For something strange is happening. When I'm selecting the check boxes ( 1 or more) and click the copy button, app is creating multiple records with blank records as well.
     
    I just need to create a duplicate copy of the selected checkboxes.
  • WarrenBelz Profile Picture
    153,721 Most Valuable Professional on at
    What exactly is colSelectd ? I was assuming it was the selected records.
  • Prem4253 Profile Picture
    652 on at
     
    colSelectd is the name given to the checkbox.
     
    Below are the property defined for this checkbox:
     
    Default: ThisItem in colSelectd
    OnCheck: Collect(colSelectd, ThisItem)
    OnUnCheck: Remove(colSelectd,ThisItem)
     
  • WarrenBelz Profile Picture
    153,721 Most Valuable Professional on at
    That is not the name of the checkbox, it is a collection (as I assumed) that is generated from the checkbox input. I assume the checkbox has a different name (if not, you need to give it one). The code you have supplied
    Default: ThisItem in colSelectd
    OnCheck: Collect(colSelectd, ThisItem)
    OnUnCheck: Remove(colSelectd,ThisItem)
    Should work, as should what I posted. What is your data source type ?
  • WarrenBelz Profile Picture
    153,721 Most Valuable Professional on at
     
    A quick follow-up to see if you received the answer you were looking for or if you need further assistance.

    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   
  • Prem4253 Profile Picture
    652 on at
     
    Something strange is still going on.
    Now when I'm selecting a date, a blank row is automatically getting created.
     
    I'm still working on the solution provided by you and trying to get the desired results, as I have multiple fields within the form.
     
    Below is the video link, which shows how to copy multiple selected records:
     
     
    If you can still advise, as where I'm going wrong. Thanks! and appreciate your help.
  • WarrenBelz Profile Picture
    153,721 Most Valuable Professional on at
    Hi @Prem4253​​​​​​​
    The video is a fairly standard process to deal with an editable gallery.
    From what I can see, you firstly manipulate a Collection, adding and deleting items with a checkbox and then when the user is satisfied, it is sent to another collection as new records and a sequential number added.
    However the main issue seems to be duplicate records, which from the code you posted, should not happen - there is only one trigger action, which is the OnCheck / OnUncheck from the checkbox. Unless you have an OnChange event on the Date Picker, it should not trigger anything, so you might check all of your controls to ensure none have this setting.
    The code I supplied earlier should not produce any duplicates.

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…

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Kalathiya Profile Picture

Kalathiya 372 Super User 2026 Season 1

#2
WarrenBelz Profile Picture

WarrenBelz 303 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 238 Super User 2026 Season 1

Last 30 days Overall leaderboard