Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Unanswered

My copied record is overwriting the existing record. What did I do?.

(0) ShareShare
ReportReport
Posted on by 825 Super User 2025 Season 1

I have a form that is used to enter a new record. It is also used when I copy a record from a gallery to create a new record. This was working for awhile until I ran into some issues with some combo boxes but that is another story. I fixed those combo boxes but now I have this issue.

 

  • When I click a copy button the selected gallery record is copied into a global variable. 
  • The user is redirected to the original form and the record values are populated into the form
  • When the form is submitted it is overwriting the record.

Do I need to switch the form back into New mode? I don't recall doing that when it was working before.

Categories:
  • Ami K Profile Picture
    15,665 Super User 2024 Season 1 on at
    Re: My copied record is overwriting the existing record. What did I do?.

    @futr_vision - I have a couple of blogs on this topic you can find below. Hopefully these will provide a more detailed explanation:

     

    https://powerusers.microsoft.com/t5/Power-Apps-Community-Blog/How-to-copy-a-record-in-a-Form-as-a-new-record-without-using/ba-p/2652476 

     

    https://powerusers.microsoft.com/t5/Power-Apps-Community-Blog/Copy-a-record-and-save-as-new-using-an-Edit-Form-and-Gallery/ba-p/2809959 

  • futr_vision Profile Picture
    825 Super User 2025 Season 1 on at
    Re: My copied record is overwriting the existing record. What did I do?.

    @Amik 

     

    Thanks. Can you help me out and explain steps one and two? It sounds like I am only using step one because I have a stand alone but I am confused. In step one you use NewForm and in step two you use EditForm. Do I not need to use EditForm?

     

    You also set the global copy variable to true in step one and the to false in step two. 

  • Ami K Profile Picture
    15,665 Super User 2024 Season 1 on at
    Re: My copied record is overwriting the existing record. What did I do?.

    @futr_vision - example:

    Recording 2024-06-18 041406.gif

  • Ami K Profile Picture
    15,665 Super User 2024 Season 1 on at
    Re: My copied record is overwriting the existing record. What did I do?.

    @futr_vision - in summary, you will need to follow the instructions provided rather than taking the parts you think you need. Some comments in blue below:

    -----------------------------------------------------------------------------------------------------------------------------

     

    For my gallery item I don't have a button per se but clicking on the item writes the record to the global variable like this:

     

    Set(
     glbFormData,
     GAL_Campaigns.Selected
    );

     

    That's fine, you would just use the OnSelect property of the Gallery control. I note however you are not setting the "gbl_copy" variable to false, which ideally, you should do.

     

    I did this because I have a form on the page, used for viewing and editing the record, that uses the global variable for the Item.

     

    Then I have a separate button for the copy function. That button uses this code when selected

     

    Set(
     glbFormData,
     GAL_Campaigns.Selected
    );
    Set(
     varCopy,
     true
    );
    EditForm(FRM_CampaignForm);
    Navigate('Create Campaign');

     

    You need to follow the instructions provided. We do not want to set the Form Mode to Edit on the Copy button, but to New.

     

    Now, for the form being copied too my datacards are just using

     

    This.'The field for this DataCard'

     

    I didn't add in a check for the varCopy since I set the Item for this form also to the global variable (varGlobalForm)

     

    You must use the formula provided for the Default property of the DataCard. Without this formula, the DataCard will simply return blank because we have set the EditForm mode to New Mode.

     

    This all works great except when I submit the form it overwrites.

     

    After reviewing your code, it looks like I need to set the form to New First and then switch it to Edit. Is that the piece I am missing?

  • futr_vision Profile Picture
    825 Super User 2025 Season 1 on at
    Re: My copied record is overwriting the existing record. What did I do?.

    @Amik 

     

    For my gallery item I don't have a button per se but clicking on the item writes the record to the global variable like this:

     

    Set(
     glbFormData,
     GAL_Campaigns.Selected
    );

     

     

    I did this because I have a form on the page, used for viewing and editing the record, that uses the global variable for the Item.

     

    Then I have a separate button for the copy function. That button uses this code when selected

     

     

    Set(
     glbFormData,
     GAL_Campaigns.Selected
    );
    Set(
     varCopy,
     true
    );
    EditForm(FRM_CampaignForm);
    Navigate('Create Campaign');

     

     

    Now, for the form being copied too my datacards are just using

     

     

    This.'The field for this DataCard'

     

     

    I didn't add in a check for the varCopy since I set the Item for this form also to the global variable (varGlobalForm)

     

    This all works great except when I submit the form it overwrites.

     

    After reviewing your code, it looks like I need to set the form to New First and then switch it to Edit. Is that the piece I am missing?

  • futr_vision Profile Picture
    825 Super User 2025 Season 1 on at
    Re: My copied record is overwriting the existing record. What did I do?.

    Thanks

  • Ami K Profile Picture
    15,665 Super User 2024 Season 1 on at
    Re: My copied record is overwriting the existing record. What did I do?.

    @futr_vision - I do not know the finer details of how you have set all this up. But the below is what way I would approach this. I assume you have already done many of these steps, but writing them all out for completeness:

     

    1. On the OnSelect property of the copy Button embedded into your Gallery control, use:

     

    Set(
     'Your Global Variable',
     ThisItem
    );
    Set(
     gbl_copy,
     true
    );
    NewForm('Your Form');
    Notify(
     "Record Copied",
     NotificationType.Success
    );//optional

     

    2. On the OnSelect property of your Gallery control, use:

     

    If(
     gbl_copy,
     Set(
     gbl_copy,
     false
     );
     Notify(
     "Copy cancelled",
     NotificationType.Warning
     )//optional
    );
    Set(
     'Your Global Variable',
     ThisItem
    );
    EditForm('Your Form')

     

    3. On the Default property for every DataCard, use:

     

    If(
     gbl_copy,
     'Your Global Variable'.'The field for this DataCard',
     ThisItem.'The field for this DataCard'
    )

     

    4. On the OnSuccess property of your EditForm:

     

    Set(
     gbl_copy,
     false
    );
    Set(
     'Your Global Variable',
     Self.LastSubmit
    );
    Notify(
     "Saved",
     NotificationType.Success
    )//optional

     

  • WarrenBelz Profile Picture
    146,700 Most Valuable Professional on at
    Re: My copied record is overwriting the existing record. What did I do?.

    Hi @futr_vision ,

    Yes - you will new New Mode on the Form if you want to write a new record.

     

    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 useful 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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

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,700 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,015 Most Valuable Professional

Leaderboard