Update SubmitForm UpdateIf or Patch

Power Apps Patch vs SubmitForm vs Update vs UpdateIf, 4 unique methods to change data

When you update a record in Power Apps you can use Power Apps Patch, SubmitForm, Update or UpdateIf, but what is the difference?

Data updates in Power Apps

In this post I’m going to assume that I have a list in SharePoint. This list will have some items in it already and I want to use Power Apps to update a list item.

I now have 4 different methods to update my data. But which option is the best one to use. It all depends on what you are trying to do.

I will go through the following approaches:

  • SubmitForm
  • Patch
  • Update
  • UpdateIf

SubmitForm

The Submitform is the easiest to use. As you create a custom form from your SharePoint list this is the default option that you could consider.

SubmitForm used in Power Apps

However using the forms within Power Apps will feel quite restrictive. All you can do is send the form content to SharePoint and then the SharePoint integration will sort out everything for you. Great for beginners, but advanced Power App-ers are likely to use the other options.

For some custom forms you might want to use the out of the box forms options, but you could also completely recreate your forms. For example if your data is stored in multiple lists then you might not want to use the form.

Power Apps Patch

The Power Apps Patch function can be used in 2 different ways. You can create an item or you can update an item. to create an item you could use the code below. The Defaults function is used to select a default new item.

Patch(
    'test list',
    Defaults('test list'),
    {
        Title: tiTitle.Text,
        Required: tiTitle_1.Text
    }
)
Power Apps Patch to update data in SharePoint list
Power Apps Patch to update a SharePoint list item

To update an existing item you first need to find the item that you want to update and then run a fairly similar piece of code as shown above. the only difference is the filter that selects the item that you want to update and then the First makes sure that it isn’t a collection of items. You want to make sure that your Power Apps Patch only needs to update.

Patch(
    'test list',
    First(Filter('test list', Id = 1 )),
    {
        Title: tiTitle_2.Text & "updated",
        Required: tiTitle_3.Text
    }
)
Power Apps Patch vs SubmitForm vs Update vs UpdateIf, 4 unique methods to change data 1

Update

The update function is fairly similar to Power Apps Patch and at first sight it looks like there is no difference other than the name of the function.

Update to update a SharePoint list item
Update to update a SharePoint list item

UpdateIf

If you want to use the update then UpdateIf is slightly nicer to use. It is not as simple as Submitform, but slightly easier than Update and Patch. No need to select the object that you want to update. Simply supply a condition. if this condition returns multiple items then multiple items will be updated.

UpdateIf(
    'test list required',   
    ID = 1,
    {
        Title: "Test",
        Required: "Test",
    }
);
Power Apps Patch vs SubmitForm vs Update vs UpdateIf, 4 unique methods to change data 2
UpdateIf to update a SharePoint list item

So which one should you use?

This is the golden question!

In general if I use forms in Power Automate then I might use the SubmitForm. Why make things any harder than they need to be. SubmitForm is definitely ok for simple forms.

Power Apps Patch is the one to use when you want to create and or update an item as it is easy to copy the code from the update to the create and visa versa.

Update has one additional parameter, All. You can use the All argument to update all copies of a record; otherwise, only one copy of the record is updated. This means that if you have multiple copies of a record you could consider using this, however I’ve never managed to make this work.

Then my personal favourite, updateIf. No need to run multiple functions to select the object/record that you want to update, you simply supply the query/condition and you can create the data that you want.

Then a final note, if you use multiple updates, the performance of the app will really benefit if you use the concurrent function in Power Apps. The concurrent function you only want to use if multiple updates at the same time is an okay thing to do. But if it is possible your app will gain a lot of speed.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: