Patch function

👆In Power Apps, the Patch function is used to update a record in a data source. It allows you to specify the data source and the new values for the record, and then it updates the record in the data source.

Here's an example of how you might use the Patch function in Power Apps:


In this example, DataSource is the name of the data source that you want to update, Record is the record that you want to update, and Field1 and Field2 are the fields in the record that you want to update with the new values Value1 and Value2, respectively.

You can use the Patch function in a variety of ways in Power Apps, including in formulas on a screen, in the OnSuccess property of a form or gallery, or in a button or other control.


👉👉Here are a few more things you might want to know about the Patch function in PowerApps:


  • You can use the Patch function to update a record in a data source that is connected to your app, such as a SharePoint list or a SQL database.
  • You can use the Patch function to update multiple records at the same time by specifying a table or collection as the record to be patched.
  • You can use the Patch function to update a record in a data source that is not connected to your app by using the ClearCollect and Collect functions to first retrieve the record from the data source, modify it, and then send the updated record back to the data source using the Patch function.
  • You can use the Patch function in combination with other functions, such as the If function, to create more complex updates. For example, you might use the If function to check the value of a field before updating it with the Patch function.
  • You can use the Patch function to update records in a data source as part of a workflow or process. For example, you might use the Patch function in the OnSuccess property of a form to update a record in a data source after the form is submitted.
You can use the Patch function to update records in a data source that has complex data types, such as multi-value fields or attachments. To update these fields, you can use the LookUp function to retrieve the current values of the fields, modify the values as needed, and then use the Patch function to update the record.

If you are updating a record in a data source that has required fields, you will need to make sure that you include all required fields in the Patch function, or the update will fail. You can use the IsBlank function to check whether a field has a value before including it in the Patch function.

If you are using the Patch function to update a record in a data source that has a unique identifier field (such as an ID field), you can use the LookUp function to retrieve the record and pass it to the Patch function as the record to be updated. This can be helpful if you don't know the exact values of all the fields in the record, but you do know the unique identifier.

The Patch function can be used to update records in data sources that are connected to your app using a variety of connectors, including SharePoint, SQL, Dynamics 365, and more. You can find a list of all the connectors supported by Power Apps on the Microsoft website.

Here is an example of how you might use the Patch function in Power Apps to update a record in a SharePoint list:





In this example, 'My SharePoint List' is the name of the SharePoint list that you want to update, and Defaults('My SharePoint List') is used to create a new record in the list with default values for all fields. The Patch function then updates the new record with the new values for the Title and Description fields.


Here is another example that shows how you might use the Patch function in combination with the LookUp function to update a record in a SQL database.




In this example, 'My SQL Table' is the name of the SQL table that you want to update, and LookUp('My SQL Table', ID = 1) is used to retrieve the record with an ID of 1 from the table. The Patch function then updates the record with the new values for the Name and Age fields.

0 Comments