You are currently viewing How PowerApps patch collection?
Patch collection

How PowerApps patch collection?

  • Post author:
  • Post category:Power Apps
  • Reading time:7 mins read

In this post, we will learn how PowerApps patch collection? you can check this article to learn more about the Power Apps Patch function.

What is the Patch function?

The patch function in PowerApps is used to create records in the data source or modify single or multiple records without affecting other properties.

Syntax :

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

How PowerApps patch collection?

You can use the power Apps patch function to modify or create a set of records in a collection.

Consider the following example: suppose we have an EmployeesCol collection containing the records listed below

  • ID
  • Name
  • Mobile
  • Email
  • Address

How to modify a record in the PowerApps Collection?

In this example, we will learn how to modify a specific value of a specific record in the employee Powerapps Collection.

PowerApps patch collection
PowerApps patch collection

How to modify the mobile number of the employee “Heba” in the Powerapps Collection?

Patch(EmployeesCol,First(Filter(EmployeesCol,Name="Heba")),{Mobile:111111111})

EmployeesCol is the data source, and we use the First function to get the first record in the collection with the name Heba and then write the update that you want to perform, here we update the mobile number.

col2 | Power Platform Geeks
Modify value with patch

This is how to use PowerApps patch collection to modify a specific record with a specific value in a collection.

Power Apps patch multiple Record

Patch(DataSource, BaseRecordsTable, ChangeRecordTable1 [, ChangeRecordTable2],…)

DataSource: It contains all of the records that you want to modify or create. Table, list, any Collection Name, etc.
BaseRecord: is used to modify or create records. If the record is retrieved from a data source, it is modified. The record is created if the result is set to Default.
ChangeRecordTable(s) = It is used to modify the properties of one or more tables of records in the BaseRecordTable.

PowerApps patch collection to SharePoint List with different column names

You can use the power Apps patch function to modify or create a set of records in a data source based on a collection.

You can use the collect function to collect data from a collection to a data source, but the collection must have the same names as the columns in the data source.

Patch(Datasource, CollectionOfChanges)

So what if you want to bind the data from the collection that have different column names? In this case, we can use the Patch function as the below examples

Suppose we have a collection that contains these fields (empname,workphone), and we want to patch these records to a SharePoint list in the columns (Title, ‘Work Phone’).

Create Collection TempCollection in the Onstart property of the app, and don’t forget to click Run OnStart to create the collection.

ClearCollect(TempCollection,{empname:”collection record1″,workphone:1645723},{empname:”collection record2″,workphone:16723})

To use PowerApps patch from the collection apply this formula

patchcol | Power Platform Geeks
PowerApps patch with collection

A common method used to update a datasource with changes from a collection uses the FORALL function to PATCH each change one-by-one.

Conclusion

In this Power Apps post we know the following :

  • What is the power Apps patch function?
  • How to Modify the value in the collection using the patch function?
  • PowerApps forall patch collection sharepoint list
  • How PowerApps patch collection to SharePoint List with different column names?
See Also
Join us
Need Help
  • Have a related question? Please ask it at deBUG.to Community.

Heba Kamal

Microsoft MVP, MCT, Technical Speaker, Blogger, and Microsoft 365 and Power Platform Consultant.