cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Updating information using multiple forms and the Patch function

Hi - 

 

I've been struggling for the last few days trying to figure out what I'm doing wrong.  

 

I have a Canvas app connected to a Sharepoint List called 'Vendor SetUp'.  It has 3 screens set up with forms to edit the data in the list and I've set up a button to send the updates to the list.  I found the below code in another post here and customized it to the app I'm working on but it doesn't update the information.

 

Patch('Vendor SetUp','Edit Vendor (V) Set Up Form - General Info'.Updates,'Edit Vendor (V) Set Up Form - Additional Info'.Updates,'Edit Temporary Activation Reason Form'.Updates)

 

Any ideas what I'm doing wrong?  

 

Thanks in advance,

 

John

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Microsoft
Microsoft

Re: Updating information using multiple forms and the Patch function

Hi@JohnNash,

Based on the issue that you mentioned, you mean that the 'Edit Vendor' is the primary key in the SP list. You want to refer to this unique value instead of ID in the SharePoint. 

Could you please share more about the 'Edit Vendor' column, is it a simple Text type or other else?

If my assumption is correct, you can modify the formula as below

 

Patch('Vendor SetUp',LookUp('Vendor SetUp','Edit Vendor'=DataCardValue6.Text),Form1.Updates,Form2.Updates)

 

If  'Edit Vendor' is a Choice column, please modify the formula as below

 

Patch('Vendor SetUp',LookUp('Vendor SetUp','Edit Vendor'=DataCardValue6.Selected.Value),Form1.Updates,Form2.Updates)

 

Note: DataCardValue6 is a control corresponding to 'Edit Vendor'.

002.png

Best Regards,

Qi

View solution in original post

9 REPLIES 9
Highlighted
Dual Super User II
Dual Super User II

Re: Updating information using multiple forms and the Patch function

The second parameter of a Patch() function should be either defaults(datasource) for creating a new record, or something like a Lookup() that identifies the existing record to be updated.  You've supplied the updates, but don't tell the system what record to update.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Highlighted
Frequent Visitor

Re: Updating information using multiple forms and the Patch function

It's to update a record. 

 

So I'm confused then.  I played a little with lookup but I'm not sure how to use it along with the Patch command?  Lookup()(Patch(listname(etc?)) or patch(lookup(listname.selected)etc?

 

 

Highlighted
Dual Super User II
Dual Super User II

Re: Updating information using multiple forms and the Patch function

Assume you have a selected Item being used to populate the forms.  The patch() to update the record would look something like this.

Patch(Datasource,Lookup(Datasource,ID = selectedItem.ID),form1.updates, form2.updates, form3.updates)


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Highlighted
Microsoft
Microsoft

Re: Updating information using multiple forms and the Patch function

Hi@JohnNash,

Do you want to update a record in an existing SharePoint list?

Let me explain the syntax in Patch() at first. You can see the standard formula as below, if you want to update an existing record, you need to find out this record and that’s what the BaseRecord means.

 

Patch( DataSource, BaseRecord, ChangeRecord1 [, ChangeRecord2, … ] )

 

The formula you provided earlier doesn’t have a BaseRecord which allows you to create a new record by default. Actually, we are used to nesting Lookup() into a Patch() to update existing data. Using the Lookup function to compare the ID(or other primary keys in your list) of the records will be the key.

Thanks for the formula @Pstork1 provided, which will solve your updating issue.

Please modify your formula as below:

 

Patch('Vendor SetUp',Lookup(‘Vendor SetUp',ID=ThisItem.ID),'Edit Vendor (V) Set Up Form - General Info'.Updates,'Edit Vendor (V) Set Up Form - Additional Info'.Updates,'Edit Temporary Activation Reason Form'.Updates)

 

Best Regards,

Qi

Highlighted
Frequent Visitor

Re: Updating information using multiple forms and the Patch function

Hi QI and PStork1,

 

I modified the formula and this is the result:

 

It didn't come across in the clip, but it's highlighting ID=ThisItem.ID as the problem.

 

Annotation 2020-06-10 085609.png

Highlighted
Dual Super User II
Dual Super User II

Re: Updating information using multiple forms and the Patch function

The use of ID and Thisitem.ID was just an example.  You need to use a field from your datasource that can identify a specific record in the datasource.  Also the thisitem assumes you are on a form.  You may need to specify the target value differently.  The point is that it should be a logical operation that Identifies the record you want to update.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Highlighted
Microsoft
Microsoft

Re: Updating information using multiple forms and the Patch function

Hi@JohnNash,

 

Considering your confusion, let me make it easy for you. In general, each data source has a primary key for easy updating, and this primary key can be any column that is unique and does not duplicate. I reference ThisItem.ID because it is the primary key in the SharePoint list by default.

 

Take a simple example, if the record you want to update is the fifth row, then the ID of this record is 5, and you can just quote it as such, ID=5. The point is that you need to find the specific ID that corresponds to the record you need to update!

 

Best Regards,

Qi

Highlighted
Frequent Visitor

Re: Updating information using multiple forms and the Patch function

I get the concept and figured out the lookup but the patching function doesn't seem to like it.. it'd be really nice if there was some error output.

 

So I was able to match using this string which is the vendor's name: Patch('Vendor SetUp',LookUp('Vendor SetUp',Name='Edit Vendor'.Name),Form1.Updates,Form2.Updates) but even then the updates are not applied.  

 

(Note the fields are different this time around, I decided to rebuild the form off an example I found.)

 

But not on this, Vendor Setup.ID is the ID column from the SharePoint list the app is connected to and the 'Edit Vendor',ID is the corresponding field in the form itself.  I've verified the value is actually correct and the field is on the form but it's expecting a Record value?  I found some references that I'll need to convert the item to a number, I assume that's the number from the sharepoint list?  (I will continue to play)

 

Annotation 2020-06-11 131518.png

 

thanks for bearing with me.

 

Highlighted
Microsoft
Microsoft

Re: Updating information using multiple forms and the Patch function

Hi@JohnNash,

Based on the issue that you mentioned, you mean that the 'Edit Vendor' is the primary key in the SP list. You want to refer to this unique value instead of ID in the SharePoint. 

Could you please share more about the 'Edit Vendor' column, is it a simple Text type or other else?

If my assumption is correct, you can modify the formula as below

 

Patch('Vendor SetUp',LookUp('Vendor SetUp','Edit Vendor'=DataCardValue6.Text),Form1.Updates,Form2.Updates)

 

If  'Edit Vendor' is a Choice column, please modify the formula as below

 

Patch('Vendor SetUp',LookUp('Vendor SetUp','Edit Vendor'=DataCardValue6.Selected.Value),Form1.Updates,Form2.Updates)

 

Note: DataCardValue6 is a control corresponding to 'Edit Vendor'.

002.png

Best Regards,

Qi

View solution in original post

Helpful resources

Announcements
Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,706)