top of page

Saving Data in Power Apps: An Introduction to the Patch Function

Hello there, Power Apps enthusiasts!

Are you looking to take your Power Apps skills to the next level? Or perhaps you're just starting out and want to learn the ropes? Either way, you're in the right place! Today, we're diving into one of the most powerful (pun intended) features of Power Apps - the Patch function.

Introduction to the Patch function

The Patch function is a game-changer when it comes to saving data in Power Apps. It's like the secret sauce that can transform your apps from good to great. But what exactly is the Patch function, and how can you use it effectively? Let's break it down.

The Patch function allows you to create and modify records in your data source. It's a step up from forms, which can be limiting when you're looking to build more complex apps. With the Patch function, you can handle individual inputs and create new records in your data source with ease.

Sounds exciting, right? But before we get ahead of ourselves, let's start with the basics.

The structure of the Patch function is pretty straightforward. You start with the function name (Patch), followed by the data source you want to update, and then the changes you want to make. It's as simple as that!

Here's a basic example of a Patch function

Patch(Employees, Defaults(Employees), {Title: "New Employee", FirstName: "John", Age: 30})

In this example, we're creating a new record in the "Employees" data source. The new record will have the Title "New Employee", the FirstName "John", and the Age 30.

A screen shot of a Power Apps function creating a new record
Saving data in Power Apps to a new record

Updating an existing record with Patch

But here's where it gets interesting. The Patch function is incredibly versatile. You can work with different data types and fields, including text, number, date, and Boolean. This means you can customize your data saving process to suit your specific needs.

For example, if you want to update an existing record, you can do so by specifying the record you want to update. Here's how you can do it:

Patch(Employees, Gallery1.Selected, {Title: "Updated Employee", Age: 31})

In this example, we're updating the record currently selected in Gallery1. We're changing the Title to "Updated Employee" and the Age to 31.

A screenshot of Power Apps Patch function updating the selected item in a gallery.
Saving data in Power Apps to update an existing item

Patching using controls

Now, let's take it a step further. Instead of hardcoding the values in our Patch function, we can use controls as inputs. This allows us to create more dynamic and interactive apps. Let's see how we can do this.

Suppose we have a text input control for the employee's first name (inpFN), a text input control for the employee's age (inpAge), and a toggle control for whether the employee is good at their job (tglGood). We can use these controls as inputs in our Patch function like this:

Patch(Employees, Gallery1.Selected, {Title: "Updated Employee", FirstName: inpFN.Text, Age: Value(inpAge.Text), GoodAtJob: tglGood.Value})

In this example, we're updating the record currently selected in Gallery1. We're changing the Title to "Updated Employee", the FirstName to the text in the inpFN control, the Age to the value in the inpAge control, and the GoodAtJob field to the value of the tglGood toggle.

A screenshot of Power Apps Patch formula updating an existing item using different control types
Saving data in Power Apps for an existing record using Power Apps controls as inputs.

This way, you can make your apps more interactive and user-friendly. Users can input their own values, and these values will be used to update the records in the data source. It's a powerful way to save data in Power Apps and make your apps more engaging.

Complete Patch walkthrough

Now, I know what you're thinking. This all sounds great, but how do you actually use the Patch function in Power Apps? Well, we've got you covered. We've created a comprehensive tutorial video that walks you through the process step by step.

In the video, we start with a blank app and a simple data source (a SharePoint list, in this case). We then demonstrate how to use the Patch function to create a new record and update existing ones. We also show you how to work with different data types and fields, and provide tips on troubleshooting and optimizing your Power Apps for better performance.

So whether you're a Power Apps newbie or a seasoned pro, this tutorial is a must-watch. It's a great introduction to the Patch function and a valuable resource for anyone looking to enhance their Power Apps skills.

Remember, saving data in Power Apps doesn't have to be complicated. With the Patch function, you can create more complex apps and manage your data more efficiently. So why wait? Dive into the world of the Patch function and start transforming your Power Apps today!

Happy patching!

8,536 views0 comments


bottom of page