cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
anabananei
Level: Powered On

Patch to Create or Update items

Hello SMEs!

 

I'm having trouble on how to patch updates in the record. I am new to powerapps and I searched similar topics in this forum (which is very helpful) but I am not able to reproduce.

 

Background: I created an app for project tracking and I successfully created a patch function for New items.

 

Here is expression: Patch('Project Tracking',Defaults('Project Tracking'),{PubSmiley Very HappyataCardValue2.Text,RelSmiley Very HappyataCardValue3.Text,'Team Lead'Smiley Very HappyataCardValue7.Selected,'Project Manager'Smiley Very HappyataCardValue8.Selected,SupervisorSmiley Very HappyataCardValue1.Selected,'Checklist Type'Smiley Very Happyropdown4.SelectedText.Value,SupplierSmiley Very Happyropdown5.Selected.Value})

 

However, if I am going to edit the item and hit the button, it creates a new item instead of updating the data. BTW, my datasource is a sharepoint list.

 

Kindly help me on this one. Thank you in advance.

Ana

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Patch to Create or Update items

Yes, you can use Patch to update an existing record without a Gallery.  As I mentioned in my reply the problem with your statement is the use of Defaults().  When you want to create a new record the second argument in the Patch statement points to the default record for the list, so it can duplicate it when creating a new record.  When updating a record the second argument should identify the specific record you want to update, not the defaults for a new record.  That's why I suggested replacing the defaults parameter with one based on First() that would supply the specific record being modified. 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
5 REPLIES 5
Super User
Super User

Re: Patch to Create or Update items

The Patch statement is about the same, but in place of Defaults('Project Tracking') you need to specify the record to be updated.  For example something like First('Project Tracking',FieldName="uniquevalue") which will return the first record where the field called FieldName is equal to the value you specify.



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

Re: Patch to Create or Update items

Hi @anabananei

 

May I know the reason why you use the Patch function instead of SubmitForm function directly? As from the formula you used, it seems that you are using all the controls inside the Form to Patch the record. 

 

If you are using the standard app auto-generated from Home > Start from data > SharePoint, then this Form's Item property should be:

BrowseGallery1.Selected

Then you could use a formula below to achieve this:

If(EditForm1.DisplayMode=New,Patch('Project Tracking',Defaults('Project Tracking'),{PubataCardValue2.Text,RelataCardValue3.Text,'Team Lead'ataCardValue7.Selected,'Project Manager'ataCardValue8.Selected,SupervisorataCardValue1.Selected,'Checklist Type'ropdown4.SelectedText.Value,Supplierropdown5.Selected.Value}),Patch('Project Tracking',BrowseGallery1,Selected,{PubataCardValue2.Text,RelataCardValue3.Text,'Team Lead'ataCardValue7.Selected,'Project Manager'ataCardValue8.Selected,SupervisorataCardValue1.Selected,'Checklist Type'ropdown4.SelectedText.Value,Supplierropdown5.Selected.Value}))

Regards,

Mona

 

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
anabananei
Level: Powered On

Re: Patch to Create or Update items

Hi @v-monli-msft  & @Pstork1 ,

 

My app is using both sharepoint data cards and some custom controls such as dropdowns. I used custom controls to replace some data cards because the flow I built does not recognize the table/record results and customizing it as a string helps my flow a lot.

 

The reason why I used patch is that it saves the data from my custom controls (dropdown) to my SharePoint list. Unlike submit form, it only saves the generated data cards and not the custom controls.


Is there a function I should and shouldn't be using?

 

Thanks!

anabananei
Level: Powered On

Re: Patch to Create or Update items

Hi @v-monli-msft ,

 

In addition, this is a customized form from SharePoint. The sample you provided for patching using the gallery could work. But in my case, I'm not using a gallery but instead, I only select the item in SharePoint and modify the fields. But then again, using my expression creates a new item instead of updating it. Is it possible to patch ti create and update without the use of gallery?

 

Thank you very much!

Super User
Super User

Re: Patch to Create or Update items

Yes, you can use Patch to update an existing record without a Gallery.  As I mentioned in my reply the problem with your statement is the use of Defaults().  When you want to create a new record the second argument in the Patch statement points to the default record for the list, so it can duplicate it when creating a new record.  When updating a record the second argument should identify the specific record you want to update, not the defaults for a new record.  That's why I suggested replacing the defaults parameter with one based on First() that would supply the specific record being modified. 



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

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, September 18th at 8am PDT

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Users Online
Currently online: 72 members 4,309 guests
Please welcome our newest community members: