Showing results for 
Search instead for 
Did you mean: 
Helper I
Helper I

Create a second record entry from gallery

I've got my app now working very nicely, however I've now been asked to be able to create a "copy" of the record. I've built a form to collect information about someone during a meeting. The users now want to be able to click a button in the gallery next to that person's name and create a second record entry, so that when they have a second meeting with the person, they're not editing the original entry. 


I have no idea where to start and am looking for help!


I need all of the information to be copied over, as if we're just editing the same record, but any changes are saved under a new recordID. When this happens, I want to edit a hidden column in my database called "Current" so that I can tell the rest of our systems which copy is the most current. 


All of my saves right now are being done using the SubmitForm function, I'm not using patch. and am using SQL. Looking for the least intrusive way to do this since it's all working perfectly right now. 


Ohh, I missed that part, sorry. Yes, putting displayitem as the items field worked, however now it's showing rnew as it was in the state before the second patch where I dropped columns. Almost there! Thank you for all of your help so far.

I'm happy to help!


Ah yes, of course! You set that variable when you did the first Patch so it keeps those values.


It should work by setting it again in the Patch where you use the collection to set all the column values, so:


Set(rNew, Patch('[dbo].[Intake_form]',{Form_Number:IDVar},First(updcoll))); Patch('[dbo].[Intake_form]',ThisItem,{Current:"N"});
Navigate(Screen1, ScreenTransition.None,{displayitem:Filter(Collection1,Form_Number=IDVar)})


I out the changes in bold italics. 


Good luck!

That did the trick!! I was about to reply and say it had reverted back to displaying the original entry again, but realized I had put the closing bracket for the SET in the wrong place. 


Here is the final code for anyone who is in a similar situation:


UpdateContext({ResetVar: true}); 
UpdateContext({ResetVar: false});
ClearCollect(updcoll, DropColumns(Collect (upd2,ThisItem),"Form_Number"));
Set(rnew,Patch('[dbo].[Intake_form]',{Form_Number:IDVar},First(updcoll))); Patch('[dbo].[Intake_form]',ThisItem,{Current:"N"});
Navigate(Screen1, ScreenTransition.None,{displayitem:rnew})

And then on the form1 screen, change the Items property to "displayitem"


Thank you very much @BitLord69, couldn't have done this without your help. 

You're welcome! And besides, it was a team effort! 🙂

Hmm... A strange side effect has happened after all of this. Previously, when I clicked the Save button when looking at the edit screen, all of the changes to the fields would disappear, and then after a few seconds come back. now... they don't reappear. The data is saved, and clicking back, and then clicking edit again shows the correct data, but this will scare my users into thinking they've lost all of their work. 


the only thing that has changed from when a user "edits" a record (instead of duplicating) is the change from ITEMS being displayItem instead of gallery.selected.  @BitLord69 any idea what change has to go along with this to get the desired action? I essentially want the form to re-load the latest values in the database after SubmitForm(Form1) fires. 


OnSuccess is the default "Collect(Collection1, Form1.Current)", I tried "Collect(Collection1, displayItem)" but that didn't make a difference. 

Update: I figured it out! the OnSuccess needed to be changed to re-set the content of displayItem:




Helpful resources

Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (4,420)