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 / How do I copy an exist...
Power Apps
Unanswered

How do I copy an existing record to create a new one?

(0) ShareShare
ReportReport
Posted on by 634

As we all know a form submission adds a new record to a datasource. I can view these records in a gallery. What I would like to do is have a button attached to each gallery record that will take that data from the record and put it back in the form and allow me to save it as a new record. Note that I am already editing records using LastSubmit.

Categories:
I have the same question (0)
  • Prakash4691 Profile Picture
    1,332 on at

    Hi @Future_Vision ,

     

    Try this,

     

    Button that attached to records in gallery, set "onselect" property to "Set(DuplicateCopy, true); EditForm(EditForm1); Navigate(EditScreen1,ScreenTransition.None)".

     

    It creates a global variable called duplicatecopy and set to true. Every time, when we click that button will know to create a copy of the record.

     

    In editform submit button, set "onselect" property to "If(DuplicateCopy = true, Patch(Accounts, Defaults(Accounts), {'Address 1: City':DataCardValue6.Text,'Account Name':DataCardValue4.Text, 'Main Phone':DataCardValue5.Text, 'Primary Contact': DataCardValue7.Selected}), SubmitForm(EditForm1)); Set(DuplicateCopy, false)".

     

    Have a check, if duplicatecopy variable is true then create new record or else edit. Finally set duplicate copy to false.

     

    Please mark it as solution. If this resolves your problem.

     

     

    Regards,

    Prakash

  • Future_Vision Profile Picture
    634 on at

    For the first part where I am setting the OnSelect for the button attached to the gallery item I see an issue. It sends me to the form but the fields don't populate. Now, this form is also set up for a 'preview' screen where the user can click edit and go back to the form. That button's code looks like this

     

    Set(glbFormData, URL4_FRM.LastSubmit); Navigate('Tracking')

     

    The values in the form are then populated using the last submitted values from the form. in the form the field's DefaultSelectedItem are set to something like {crfeb_choice:Parent.Default} to populate the values. Do I need to leverage that glbFormData variable to get the form populated? Maybe some type of patch that puts the record's values into that variable?

  • Prakash4691 Profile Picture
    1,332 on at

    @Future_Vision ,

     

    What is the issue for button added in gallery item?

     

    So, in gallery if we select any record for edit it always populates with last submit?

     

    Could you please ellobarote your requirement?

     

     

  • Abhishek Gawde Profile Picture
    96 on at

    Hello @Future_Vision,

     

    Here is how i solved it. Very similar to what @Prakash4691 suggested.

     

    1. Added a Button to the Gallery.

      abhishekgawde_0-1618600385137.png

    2. Then I set the "OnSelect" property to Set(varCopy,ThisItem);
    3. Then I used the Patch like this Patch(Source, Defaults(Source),{Column1:varCopy.Column1.value,Column1:varCopy.Column1.value,....})

    This will create a new Item in the data source, with the values filled using the copied item from the gallery. The key here is to use the "Defaults". I have successfully done this for SharePoint as a data source. Would be interesting to see if this work for Dataverse as well.

     

    Hope this help. Happy to answer any questions you might have. Also if there is any better way to solve this, then please let us all know 🙂

     

    Happy Learning! 

  • Future_Vision Profile Picture
    634 on at

    The app goes through this workflow

     

    Form Fill > Data 'Review' Screen > The the user can Edit which send them back to the Form Fill screen or the can navigate to their Gallery. 

     

    Their Gallery screen is split into two galleries. One gives a preview of all of their records. When you click on the record the second gallery fills with all of the data from the record. I'm trying to add a button to that second gallery that sends them back to the Form Fill screen where all of the data from the selected record is populated in the form. Next time they submit it should be entered into the data source as a new record.

  • Future_Vision Profile Picture
    634 on at

    This is an interesting solution but I question creating the new record prior to the updates made in the form. They may want to cancel out of the copy process and duplicating a record in the Dataverse is probably not the way to go unless you can somehow delete the record if they cancel out of the process. Make sense?

  • Abhishek Gawde Profile Picture
    96 on at

    Hello @Future_Vision 

     

    You can easily solve this. Just create a dialog box which will prompt the user with a question and two buttons (yes/ no). Use the Patch formula on the "OnSelect" property of the "yes" button, and for the "no" button, just do nothing and navigate the user back.

     

    abhishekgawde_0-1618606381301.png

  • Future_Vision Profile Picture
    634 on at

    @abhishekgawde With your example you are saying that a single button is going to play a dual role - edit or copy? I don't want them to edit existing records in their gallery. At that point they need to request changes instead via email functionality I built in. I only want them to have the ability to copy an existing campaign and save it as new. 

     

    Now, I was able to do something like this which grabs the record and populates the form. The only problem is the submissions edits the record instead of saving as a new record.

     

    Set(glbFormData, ThisItem); Navigate('Tracking')
  • Future_Vision Profile Picture
    634 on at

    @abhishekgawde 

    Is it possible to take the current behavior I achieved above using the glbFormData and tell PowerApps that I am not editing the record but creating a new one? Maybe there is a better way to get the data from the record into a variable and use that to fill the form.

  • Abhishek Gawde Profile Picture
    96 on at

    @Future_Vision 

     

    Yes you can. Use the glbFormData to create a new record by using Patch+Defaults formula.

     

    Create another button, and set the OnSelect property to:

     

    Patch(Source, Defaults(Source),{Column1:glbFormData .Column1.value,Column2:glbFormData .Column2.value,....})

     

    https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-defaults

    https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch

     

    Hope this helps.

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 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard