Are you looking to modify or create one or more records in a data source, or merge records outside of a data source? Then you need to use the Patch function in Power Apps. In this article, we will explain how to use the Patch function with examples.

Key Takeaways

Here are some key takeaways from this article:

Key Takeaways
The Patch function is used to modify or create one or more records in a data source, or merge records outside of a data source.
You can use the Patch function to modify records in complex situations, such as when you do updates that require no user interaction or use forms that span multiple screens.
To update records in a data source more easily for simple changes, use the Edit form control instead.
The syntax of the Patch function is Patch( DataSource, BaseRecord, UpdateRecord1 [, UpdateRecord2, ... ] ).
You can use the Patch function to modify a record, create a record, or merge two records.

What is the Patch function?

The Patch function in Power Apps is used to modify or create one or more records in a data source, or merge records outside of a data source. You can use it to modify records in complex situations, such as when you do updates that require no user interaction or use forms that span multiple screens. To update records in a data source more easily for simple changes, you can use the Edit form control instead.

Syntax of the Patch function

The «Patch» function used to update data in a data source in PowerApps.

Here is the syntax of the «Patch» function:

Patch ( DataSource, BaseRecord, UpdateRecord1 [, UpdateRecord2, ... ] )
  • DataSource: The data source to modify or create records in.
  • BaseRecord: The record to modify or create.
  • UpdateRecord: One or more records that contain new property values that override property values in the base record.

More information: Microsoft

Examples of how to use the Patch function

Here are some examples of how to use the Patch function:

  • Modify a Record: Patch( Customers, First( Filter( Customers, Name = "Contoso" ) ), { Phone: "1-212-555-1234" } )
  • Create a New Record: Patch( Customers, Defaults( Customers ), { Name: "Contoso" } )
  • Merge two Records: Patch( { Name: "Contoso", Phone: "1-212-555-1234" }, { Name: "Contoso", Location: "Midtown" } )

 

How to use Power Apps Patch Function to Modify/Update an Existing Record?

Let’s start with the basics. We’ll walk through a simple example of using PATCH to modify a single record. This foundational understanding will serve as a stepping stone for more complex scenarios.

Patch( Orders, LookUp ( Orders, ID = 1), { Quantity: 15 } )

The values of specific fields are modified without affecting other properties. For example, this formula changes the Quantity = 15 for an Order ID=1.

Power Apps Patch Example to Generate/Create a New Record?

Use Patch with the Defaults function to create records.

Patch( Customers, Defaults( Orders ), { ID: 10, Article: "Jacket", Date: Today(), Quantity: 2 } )

How to Obtain the Power Apps Patch Function‘s Output?

Retrieve the updated Record:

Set( varOrderUpdated, Patch( Customers, Defaults( Orders ), { ID: 10, Article: "Jacket", Date: Date(2023,1,1), Quantity: 2 } ) )

 

Best practices for using the Patch function

Here are some best practices for using the Patch function:

  1. Use the Patch function to modify records in complex situations, such as when you do updates that require no user interaction or use forms that span multiple screens.
  2. To update records in a data source more easily for simple changes, use the Edit form control instead.
  3. Use the Patch function to modify a record, create a record, or merge two records.
  4. Error Handling and Debugging Tips: No development process is without its challenges. Uncover tips for effective error handling and debugging to streamline your Power Apps development workflow. More info: Click Here

What is the Patch function in Power Apps?

The Patch function in Power Apps is used to modify or create one or more records in a data source, or merge records outside of a data source.

When should I use the Patch function?

You should use the Patch function when you need to modify or create records in a data source or merge records outside of a data source. It is useful in complex situations or when updates require no user interaction.

What is the syntax of the Patch function?

The syntax of the Patch function is: Patch(DataSource, BaseRecord, UpdateRecord1[, UpdateRecord2,… ])

Is PATCH the only function for data manipulation in Power Apps?

No, Power Apps offers various functions. PATCH stands out for its precision in updating records.

Can I use the Patch function to create new records?

Yes, you can use the Patch function to create new records. Use it with the Defaults function to set initial values for the new records.

What are some best practices for using the Patch function?

Best practices for using the Patch function include employing it in complex situations, using the Edit form control for simple changes, and handling errors effectively.

How do I get the result of the Patch function?

You can retrieve the updated record using a formula like Set( varOrderUpdated, Patch( DataSource, BaseRecord, UpdateRecord ) )

How do I use the Patch function?

To use the Patch function, you need to specify the data source, base record, and change record(s).

What are some examples of how to use the Patch function?

Examples of how to use the Patch function include modifying a record, creating a record, and merging two records.

How do I create a new record with the Patch function?

To create a new record with the Patch function, use the Defaults function to create a base record.

How do I update an existing record using the Patch function?

To update an existing record using the Patch function, use the LookUp function to find the record you want to update and then specify the changes you want to make.

Power Apps Patch Function - Frequently Asked Questions(FAQ)

Conclusion

In conclusion, the Patch function is a powerful tool that can be used to modify or create one or more records in a data source, or merge records outside of a data source. By following the best practices outlined in this article, you can use the Patch function to modify records in complex situations, such as when you do updates that require no user interaction or use forms that span multiple screens. If you need help with Power Apps consulting services, please contact us at HakoIT.com.

Stay tuned for more informative articles on Power Apps and other software solutions!

Free Power Apps Tutorials and Guides:

Do you want to continue learning about Power Apps? Below is a simple and easy beginner’s tutorial for creating an application with a SharePoint or Excel list:

How to build an app in 30 Seconds – Sharepoint | Microsoft Power Apps

Create an APP with EXCEL in 5 Steps

Power Apps Copilot AI Tutorial

How to create a Power Apps Custom Connector | API The Complete Guide

👉 Contact us for more information or schedule a meeting.

Facundo Capdevila

Facundo Capdevila

[related_posts_by_tax format=»thumbnails» image_size=»medium» posts_per_page=»3″]