cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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. 

15 REPLIES 15
Highlighted

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"});
EditForm(Form1);
Navigate(Screen1, ScreenTransition.None,{displayitem:Filter(Collection1,Form_Number=IDVar)})

 

I out the changes in bold italics. 

 

Good luck!

Highlighted

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});
 Set(rnew,Patch('[dbo].[Intake_form]',Defaults('[dbo].[Intake_form]'),
{First_Name:ThisItem.First_Name}));
Set(IDVar,rnew.Form_Number);
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"});
EditForm(Form1); 
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. 

View solution in original post

Highlighted

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

Highlighted

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. 

Highlighted

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

 

Set(displayItem,Collect('[dbo].[Intake_form]',displayItem))

 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (8,702)