web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch with ThisItem
Power Apps
Answered

Patch with ThisItem

(0) ShareShare
ReportReport
Posted on by 218

Hi, looking for some additional insight on creating a patch command for the OnSelect button with a SQL Server backend.  Is there a simple patch command, highlighting each card (e.g. {First_Name:DataCardValue123.Text}), that I can create that uses a "ThisItem" so it does not create a new record each time?

 

***** Side-note / Not using any FK's in my tables. *****

 

Here's what I'm doing now.


For my primary table I use the following.  This works perfect (I believe)...doesn't seem to work with the other tables I've added(dbo.company, dbo.contacts).

If( // Check if you are adding or editing record
EditForm_Audits_Company.Mode = FormMode.New,
Patch(
'[dbo].[audits]',
Defaults('[dbo].[audits]'),
EditForm_Audits_Company.Updates
);Navigate(BrowseGallery_Audits),
Patch(
'[dbo].[audits]',
BrowseGallery_Audits.Selected,
EditForm_Audits_Company.Updates
);Navigate(Screen_Detail_Audits_Company)
)

 

For the other tables this same code does not work (below).

 

Non-Working Code / Copy and paste from my main table (dbo.audit)

 

If( // Check if you are adding or editing record
EditForm_Company.Mode = FormMode.New,
Patch(
'[dbo].[company]',
Defaults('[dbo].[company]'),
EditForm_Company.Updates
);Navigate(BrowseGallery_Company),
Patch(
'[dbo].[company]',
BrowseGallery_Company.Selected,
EditForm_Company.Updates
);Navigate(Screen_Detail_Company)
)

Categories:
  • Rebetcha Profile Picture
    645 on at

    Hi @ez1138 ,

     

    It looks like you are using a form control. Why not use the SubmitForm formula? That formula takes care of either creating a new record or editing an existing record based on the FormMode so you do not have to work this out.

  • ez1138 Profile Picture
    218 on at

    Thanks for the reply.  Maybe because I use SQL Server, maybe I just saw "patch" all over the place.  Prior to trying it out, a couple extra questions.

     

    • Is "patch" used for non-forms apps?
    • Does the regular SubmitForm(form_name) I will be trying update SQL?
      • I will probably answer that question for myself and the other soon

    Thanks again and fingers crossed!

  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @ez1138 ,

    For your first question, Yeah, you are right. If you do not use Edit form in your canvas app, and want to patch data back to your SQL Table, I think the Patch function may be the best choice for you.

    Of course, if you use Edit form in your canvas app to collect user entry, you still could use Patch function to submit form data back to your SQL Table without using SubmitForm() function.

     

    Regarding the Patch formula that you mentioned, I could not find any syntax issue with it. Please make sure you have defined a proper Primary Key in your '[dbo].[company]' SQL Table already. In addition, also please make sure the EditForm_Company is connected to your '[dbo].[company]' table properly (DataSource property of the EditForm_Company has been set to '[dbo].[company]').

    For your scenario, you could simplify your Patch formula as below:

    Patch(
     '[dbo].[company]',
     If(
     EditForm_Company.Mode = FormMode.New,
     Defaults('[dbo].[company]'),
     BrowseGallery_Company.Selected
     ),
     EditForm_Company.Updates
    );
    If(
     EditForm_Company.Mode = FormMode.New,
     Navigate(BrowseGallery_Company),
     Navigate(Screen_Detail_Company)
    )

     

    For your second question, if you want to use SubmitForm(EditForm_Name) function to submit your form data back to your SQL Table to update an existing record, you must make sure the DefaultMode property of the Edit form has been set to following:

    FormMode.Edit

    and the Item property of the Edit form has been set to following:

    BrowseGallery_Company.Selected

     

    More details about Patch function, and SubmitForm function in PowerApps, please check the following artilce:

    Patch function, SubmitForm function

     

    If the issue still exists, please consider remove the '[dbo].[company]' table connection from your canvas app, then re-create a new connection to your '[dbo].[company]' table again from your canvas app, try above Patch formula again, check if the issue is solved.

     

    Best regards,

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 354 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 320

#3
Mohsin Ali Profile Picture

Mohsin Ali 246

Last 30 days Overall leaderboard