cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
CVannest
Helper III
Helper III

Retreieve a record, edit and submit as new

I've built my PowerApp and it's almost ready for production.

During the testing, one request came in that I would like to incorporate.

When a submitter comes back to the form to update a submission, I'd like to have a dropdown box where they could select a previous "Ticket Number" and it will pull the details of that ticket number into the form so they can edit items and re-submit it as a NEW entry into the SharePoint List.  I don't want it to EDIT the previous entry, just re-use some of the data so they're not re-entering all the fields again.

 

The form is "Form1" and the field I want them to be able to search on to retrieve the old information is DataCardValue17 from SP List "Outages,'What is the Ticket Number"

19 REPLIES 19
RandyHayes
Super User
Super User

@CVannest 

So your item property is Gallery1.Selected...

Change that to: Patch(Gallery1.Selected, {ID: Blank()})

Now when you submit the form, it will create a new record with all the existing data.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
CVannest
Helper III
Helper III

You just earned another 5 coffees man!!!!!  You ARE a "Super User"!!!!

RandyHayes
Super User
Super User

@CVannest 
LOL - yay...more "awake" time 😜

 

This is all part of one of the wonders of the Edit form...manipulating the Item record. 

 

It also dovetails nicely with the concept of the Patch function.  IF you supply a primary key to the Patch function, it will find and update that record.  If you do NOT supply a primary key (blank), then it will Create a record.

The form works the same way.

 

New mode on a form means that the form will automatically generate the record for the form, and it will do so on Defaults(yourDataSource), but you will have NO access to that record - it is internal to the form.

With Edit mode, you can do the exact same thing...put Defaults(yourDataSource) in the Item property ant it is identical to the New form.

 

Where the magic comes is that you can have your form in Edit mode and manipulate the Item record as much as you like.  So, for example, if you want a Title column to have a certain value to it, then you can set your Item property to:  Patch(Gallery1.Selected, {Title: "Certain Value"}))

Now, your form will be a new record AND the Title column will already be filled in.

 

This is all great for setting values to be in the form, but if you want to then make an existing record (in your case Gallery1.Selected) to be a new record with all the data that is in that existing record, then we just Patch the ID column (the primary key) to Blank().  Now the form has all the data and when you submit, it will see no key and thus create a new record.

 

All fun stuff!!

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Very neat solution - I certainly learned something new!

RandyHayes
Super User
Super User

@CVannest 

OH...and to just add for clarity...if you DO issue a NewForm function anywhere on that form, New mode will completely ignore the Item property.  It will then just be a new blank record.  So, stick with EditForm, or just leave the form default as Edit.  Manipulate the Item property to get what you want the form to do.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

I did some testing after implementing the code.

It's still just updating the record that I pulled back over from my gallery.

If I change DefaultMode to FormMode.Edit I can't clear the fields with my reset icon up top.

 

CVannest_0-1645734882637.png

 

RandyHayes
Super User
Super User

@CVannest 

Your form mode is set to New in that photo.  You need to make sure it is Edit and you need to make sure you are not issuing a NewForm anywhere.

Using ResetForm and that when in Edit mode with a record in the Items will only reset the form to what the record is, so you will want to change to a variable instead of simply selecting the Gallery1.Selected.

 

In your Gallery OnSelect (or whatever you are using to get to the form from the Gallery), add the following:  Set(glbCurrentRecord, ThisItem)  

Then change the Item property of the Form to:  Patch(glbCurrentRecord, {ID:Blank()})

In the reset/refresh or whatever that icon is at the top for, that will need to be: Set(glbCurrentRecord, Defaults(Outages))

That will then show your form with a new record.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
CVannest
Helper III
Helper III

Okay, so OnSelect for the pencil on my Gallery1 is set to what's below in the photo.

I should change the code here to what's above or put it before/after? 

 

Change DefaultMode on Form1 on Home page of my app to FormMode.Edit - Easy...done.

 

CVannest_0-1645740457674.png

 

CVannest
Helper III
Helper III

I think I got it....the entire GALLERY1 needed the statement put in ON SELECT.
So user clicks the item, then clicks the pencil and that item will go to the Form to be edited and then submit as new record.  Testing it now!

RandyHayes
Super User
Super User

@CVannest 

Well, depends!  If you want a user to click on any part of the Gallery to go to that screen, then the Gallery OnSelect is the place.  If you only want them to click on the Pencil Icon, then the OnSelect of the Icon is the place to put it.

So, for the Pencil Icon, the OnSelect would be:

Set(glbCurrentRecord, ThisItem);
Navigate(Home)

If the form is in Edit mode as default, you don't need the EditForm part.

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (1,796)