Patch

How to Use the Power Fx Patch  Function in Power Apps

Understanding the Power Fx Patch Function

The Power Fx Patch function is an essential tool for updating data in a data source, such as SharePoint or Excel. It allows you to modify an existing record or create a new record. The syntax of the Power Fx Patch function is as follows:


Patch(dataSource, recordToUpdate, changes)


- **dataSource**: This parameter identifies the data source you want to modify.

- **recordToUpdate**: This parameter specifies the record you want to update or create. You can use the `LookUp` function to identify the record you want to update.

- **changes**: This parameter is a collection of changes you want to make to the record. Each change is composed of a column name and a value.

Updating an Existing Record

To update an existing record, you need to identify the record you want to update using the `LookUp` function. The `LookUp` function searches for a record that matches a specific condition. For example, if you want to update the record with the name "John" in the SharePoint list "Employees," you can use the following formula:


LookUp(Employees, Name = “John”)


This formula searches the "Employees" list for a record with the name "John." Once you have identified the record you want to update, you can use the Power Fx Patch function to modify the record. For example, if you want to update John's phone number, you can use the following formula:


Patch(Employees, LookUp(Employees, Name = “John”), {Phone: “555-555-5555”})


This formula updates the "Phone" column of the "Employees" list for the record with the name "John" to "555-555-5555."

Creating a New Record

To create a new record, you can use the Power Fx Patch function without the `LookUp` function. For example, if you want to create a new record in the "Employees" list with the name "Jane" and the phone number "555-555-5556," you can use the following formula:


Patch(Employees, Defaults(Employees), {Name: “Jane”, Phone: “555-555-5556”})


This formula creates a new record in the "Employees" list with the name "Jane" and the phone number "555-555-5556."

The Power Fx Patch function is a powerful tool that allows you to modify and create records in a data source. With its easy-to-use syntax and flexibility, you can update and create records without requiring expert knowledge in coding. By understanding how to use the Power Fx Patch function, you can create powerful and customized business applications in Power Apps.

Power Apps Training Courses by G Com Solutions (0800 998 9248)