Patch function in Power Apps (contains video) - Power Platform (2023)

  • Article
  • 8 minutes to read

Modifies or creates one or more records in a data source, or merges records outside of a data source.

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. When you add an Edit form control, you provide users with a form to fill in and then save the changes to a data source. For more information, see Understand data forms.

Watch this video to learn how to use the Patch function:

Overview

Use the Patch function to modify one or more records of a data source. The values of specific fields are modified without affecting other properties. For example, this formula changes the phone number for a customer named Contoso:

(Video) How to use PATCH Function in Power Apps | Insert and Update data

Patch( Customers, First( Filter( Customers, Name = "Contoso" ) ), { Phone: "1-212-555-1234" } )

Use Patch with the Defaults function to create records. Use this behavior to build a single screen for both creating and editing records. For example, this formula creates a record for a customer named Contoso:

Patch( Customers, Defaults( Customers ), { Name: "Contoso" } )

Even if you're not working with a data source, you can use Patch to merge two or more records. For example, this formula merges two records into one that identifies both the phone number and the location for Contoso:

Patch( { Name: "Contoso", Phone: "1-212-555-1234" }, { Name: "Contoso", Location: "Midtown" } )

Description

Modify or create a record in a data source

To use this function with a data source, specify the data source, and then specify a base record:

  • To modify a record, the base record needs to have come from a data source. The base record may have come through a gallery's Items property, been placed in a context variable, or come through some other path. But, you can trace the base record back to the data source. This is important as the record will include additional information to help find the record again for modification.
  • To create a record, use the Defaults function to create a base record with default values.

Then specify one or more change records, each of which contains new property values that override property values in the base record. Change records are processed in order from the beginning of the argument list to the end, with later property values overriding earlier ones.

(Video) Power Apps Patch function with SharePoint Columns

The return value of Patch is the record that you modified or created. If you created a record, the return value may include properties that the data source generated automatically. However, the return value doesn't provide a value for fields of a related table.

For example, you use Set(MyAccount, Patch(Accounts, First(Account), 'Account Name': "Example name")); and then MyAccount.'Primary Contact'.'Full Name'. You can't yield a full name in this case. Instead, to access the fields of a related table, use a separate lookup such as:

LookUp(Accounts, Account = MyAccount.Account).'Primary Contact'.'Full Name'

When you update a data source, one or more issues may arise. Use IfError and IsError with the return value from Patch to detect and respond to errors, as Error Handling describes. You can also use the Errors function to identify and examine issues, as Working with Data Sources describes.

Related functions include the Update function to replace an entire record, and the Collect function to create a record. Use the UpdateIf function to modify specific properties of multiple records based on a condition.

Modify or create a set of records in a data source

Patch can also be used to create or modify multiple records with a single call.

Instead of passing a single base record, a table of base records can be provided in the second argument. Change records are provided in a table as well, corresponding one-for-one with the base records. The number of records in each change table must be the same as the number of records in the base table.

When using Patch in this manner, the return value is also a table with each record corresponding one-for-one with the base and change records.

(Video) Patch Function in Power Apps

Merge records outside of a data source

Specify two or more records that you want to merge. Records are processed in the order from the beginning of the argument list to the end, with later property values overriding earlier ones.

Patch returns the merged record and doesn't modify its arguments or records in any data sources.

Syntax

Modify or create a record in a data source

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

  • DataSource – Required. The data source that contains the record that you want to modify or will contain the record that you want to create.
  • BaseRecord – Required. The record to modify or create. If the record came from a data source, the record is found and modified. If the result of Defaults is used, a record is created.
  • ChangeRecord(s) – Required. One or more records that contain properties to modify in the BaseRecord. Change records are processed in order from the beginning of the argument list to the end, with later property values overriding earlier ones.

Modify or create a set of records in a data source

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

  • DataSource – Required. The data source that contains the records that you want to modify or will contain the records that you want to create.
  • BaseRecordTable – Required. A table of records to modify or create. If the record came from a data source, the record is found and modified. If the result of Defaults is used, a record is created.
  • ChangeRecordTable(s) – Required. One or more tables of records that contain properties to modify for each record of the BaseRecordTable. Change records are processed in order from the beginning of the argument list to the end, with later property values overriding earlier ones.

Merge records

Patch( Record1, Record2 [, …] )

  • Record(s) - Required. At least two records that you want to merge. Records are processed in order from the beginning of the argument list to the end, with later property values overriding earlier ones.

Examples

Modify or create a record (in a data source)

In these examples, you'll modify or create a record in a data source, named IceCream, that contains the data in this table and automatically generates the values in the ID column:

Patch function in Power Apps (contains video) - Power Platform (1)

(Video) Patch, Update and UpdateIf functions in Power Apps

FormulaDescriptionResult
Patch(IceCream,
LookUp( IceCream, Flavor = "Chocolate" ), {Quantity:400} )
Modifies a record in the IceCream data source:
  • The ID column of the record to modify contains the value of 1. (The Chocolate record has that ID.)
  • The value in the Quantity column changes to 400.
{ID:1, Flavor:"Chocolate", Quantity:400 }

The Chocolate entry in the IceCream data source has been modified.

Patch( IceCream, Defaults(IceCream ), {Flavor:"Strawberry"})Creates a record in the IceCream data source:
  • The ID column contains the value 3, which the data source generates automatically.
  • The Quantity column contains 0, which is the default value for that column in the IceCream data source, as the Defaults function specifies.
  • The Flavor column contains the value of Strawberry.
{ ID:3, Flavor:"Strawberry", Quantity:0}

The Strawberry entry in the IceCream data source has been created.

After the previous formulas have been evaluated, the data source ends with these values:

Patch function in Power Apps (contains video) - Power Platform (2)

Merge records (outside of a data source)

FormulaDescriptionResult
Patch({Name:"James",Score:90}, {Name:"Jim",Passed:true} )Merges two records outside of a data source:
  • The values in the Name column of each record don't match. The result contains the value (Jim) in the record that's closer to the end of the argument list instead of the value (James) in the record that's closer to the start.
  • The first record contains a column (Score) that doesn't exist in the second record. The result contains that column with its value (90).
  • The second record contains a column (Passed) that doesn't exist in the first record. The result contains that column with its value (true).
{Name:"Jim", Score:90, Passed:true}

Use of As or ThisRecord

Using the As or ThisRecord keyword in the formula avoids ambiguous evaluation context.

In the example below, consider the first lookup in the If statement. (OrderID = A[@OrderID]) is expected to compare the OrderId in the lookup scope with the OrderId of collection A in the ForAll scope. In this case, you likely want A[@OrderId] to be resolved as a local parameter. But it is ambiguous.

Power Apps currently interprets both the left-hand side OrderId and right-hand side A[@OrderId] as a field in the lookup scope. Therefore, lookup will always find the first row in [dbo].[Orders1] because the condition is always true (that is, any row's OrderId is equal to itself.)

ClearCollect( A, Filter( '[dbo].[Orders1]', OrderId = 8888888 ));ForAll( A, If( LookUp( '[dbo].[Orders1]', OrderId = A[@OrderId], "OK" ) = "OK", Patch( '[dbo].[Orders1]', LookUp( '[dbo].[Orders1]', OrderId = A[@OrderId] ), {OrderName: "val1" }),Patch( '[dbo].[Orders1]', Defaults('[dbo].[Orders1]'), {OrderName: "val2" }) ))

Using As or ThisRecord

Whenever possible use the As operator or the ThisRecord to disambiguate the left-hand side. As is recommended for the above scenario.

When your formula uses multiple scopes with ForAll, Filter, and Lookup on the same data source or table, it is possible that the scope parameters may collide with a same field elsewhere. Therefore, it is recommended to use the As operator or ThisRecord to resolve the field name and avoid ambiguity.

(Video) Save or Update record in PowerApps | SubmitForm | Patch | PowerApps for beginners | Power Platform

For example, you can use the As operator to disambiguate in the example below.

ClearCollect( A, Filter( '[dbo].[Orders1]', OrderId = 8888888 ));ForAll( A, If( LookUp( '[dbo].[Orders1]' As B, B.OrderId = A[@OrderId], "OK" ) = "OK", Patch( '[dbo].[Orders1]', LookUp( '[dbo].[Orders1]' As C, C.OrderId = A[@OrderId] ), {OrderName: "val1" }),Patch( '[dbo].[Orders1]', Defaults('[dbo].[Orders1]'), {OrderName: "val2" }) ))

Alternatively, you can use ThisRecord for the same purpose.

ClearCollect( A, Filter( '[dbo].[Orders1]', OrderId = 8888888 ));ForAll( A, If( LookUp( '[dbo].[Orders1]', ThisRecord.OrderId = A[@OrderId], "OK" ) = "OK", Patch( '[dbo].[Orders1]', LookUp( '[dbo].[Orders1]', ThisRecord.OrderId = A[@OrderId] ), {OrderName: "val1" }),Patch( '[dbo].[Orders1]', Defaults('[dbo].[Orders1]'), {OrderName: "val2" }) ))

To learn more about the usage of As operator and ThisRecord see Operators article.

FAQs

What does the Patch function do in Power Apps? ›

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.

What is difference between Patch and update in Power Apps? ›

Modify Record

As you can see, Update and Patch are almost the same, with the difference the same difference between PATCH and PUT (Update replaces the record, so all fields need to be included, else they will be null). So I would say Patch supersedes Update in most cases.

What is a patch and what is it used for? ›

A patch is a software update for an existing application or operating system to resolve bugs (errors) or vulnerabilities.

What is a patch and how does it work? ›

The patch releases a daily dose of hormones through the skin into the bloodstream to prevent pregnancy. It contains the same hormones as the combined pill – oestrogen and progestogen – and works in the same way by preventing the release of an egg each month (ovulation).

Can we use Patch for collection Power Apps? ›

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.

How do I Patch a choice column in Power Apps? ›

Enter the PowerApps name and it will redirect to the PowerApps Studio.
  1. Click blank App.
  2. Create Choices Field in Data verse. ...
  3. Now display the Form Control to Add new values into Dataverse Table. ...
  4. Submit Button's On select Write the code like this, ...
  5. Adding New item,
  6. Let's validate the DataTable, the new Record has been added,
Jun 10, 2022

How do I Patch a date field in Power Apps? ›

Power Apps date picker patch blank date

Let's preview the app and insert the data in both controls. While clicking on the Save button, we can see instead of the selected date, it will patch a blank value from the Power Apps to date source.

What is difference between submit and patch function? ›

With an Edit Form we use the SubmitForm function to save form data back to a SharePoint list. When building a Power Apps Patch Form our own form we must use the Patch function instead to submit data. The Patch function creates a new record or modifies an existing record in a datasource.

What is the difference between a patch and an upgrade? ›

Patches minimize your attack surface and protect your system against attackers. “While general software updates can include lots of different features, patches are updates that address specific vulnerabilities.”

What is the difference between patch and version? ›

A patch is offered to users who currently own a license for a version of the software that has the same major revision number as the new release. For example, if a user owns version 1 of the software and version 1.1 is released, the user can download a patch free of charge from our website.

Which command is used for bulk patch? ›

Patch(ChecklistItemsSource , CheckedItems)

Using ForAll and Patch: In many scenarios, the columns in source and destination tables vary and you cannot use the Patch statement, but instead use ForAll with Patch. With ForAll, you must loop through each record using a condition.

What are the two types of patches? ›

Patches 101: The 7 Different Kinds of Patches
  • Embroidered patches.
  • PVC patches.
  • Chenille patches.
  • Woven patches.
  • Leather patches.
  • Name patches.
  • Printed patches.
  • Bullion patches.
Jan 17, 2019

Why do we need to apply patch? ›

Security: Patch management fixes vulnerabilities on your software and applications that are susceptible to cyber-attacks, helping your organization reduce its security risk. System uptime: Patch management ensures your software and applications are kept up-to-date and run smoothly, supporting system uptime.

Why do we apply patches? ›

Along with other updates like dot-releases to (or complete overhauls of) an operating system, patches are part of essential preventative maintenance necessary to keep machines up-to-date, stable, and safe from malware and other threats.

When should a patch be applied? ›

You can start using the birth control patch as soon as you get it — any day of the month, and anytime during your menstrual cycle. But depending on when you start the patch, you may need to use a backup birth control method (like condoms) for the first 7 days.

Where should the patch be applied and how should it be used? ›

You can place the patch on your buttock, upper outer arm, lower abdomen or upper body. Don't put it on your breasts or in a place where it will be rubbed, such as under a bra strap. Apply to skin that's clean and dry. Avoid areas of the skin that are red, irritated or cut.

Can Patch create a new resource? ›

The list of changes are supplied in the form of a PATCH document. If the requested resource does not exist then the server may create the resource depending on the PATCH document media type and permissions.

How do I merge two collections in PowerApps? ›

Firstly, combine collection2 with collection1 by using the same code that collection1 and collection2 both have. Then collect the code that only collection2 has to the step1's collection. If this post helps, then please consider Accept it as the solution.

What does Patch return? ›

The PATCH method could return a number of different status codes. For a successful PATCH, common status codes would likely be 200 (OK) or 204 (No Content). If the PATCH method was unsuccessful, status codes such as 304 (Not Modified), 400 (Bad Request), or 422 (Unprocessable Entity) may be seen.

How do I patch a group or person in PowerApps? ›

To patch a person field in SharePoint you'll want the following syntax.. This patch submits to 2 fields Title and Requestor. If you want to patch say your manager - you would set variables using the o365users connection to get your manager and set values for claims, department, displayname and email.

How do I patch a combobox value in PowerApps? ›

Power Apps patch combo box multiple values

On the SharePoint list, set the toggle on the choice column(i.e., WorkMode) to “allow multiple selections.” For this, select the choice column > Column Settings > Edit > More Options > Allow multiple selection > Toggle On > Save.

How do you patch data in Dataverse table? ›

How to get data from Dataverse in Power Apps
  1. Create Power Apps Canvas App With Data From Microsoft Dataverse.
  2. Save Power Apps Canvas App.
  3. Various Screens in Power Apps Canvas App. BrowseScreen1: DetailScreen1: EditScreen1:
  4. Refresh Dataverse Table in Power Apps Canvas App.
Nov 2, 2022

How do I compare two dates in Power Apps? ›

Example here https://powerusers.microsoft.com/t5/PowerApps-Forum/Using-numbers-and-dates-from-SharePoint-lists/m-... - Then, use DateDiff function to compare 2 dates. You can go here (Formular Reference) for more information.
...
Compare date
  1. Date.
  2. function.
  3. SharePoint.

How can I get current date and time in Power Apps? ›

The Now function returns the current date and time as a date/time value. The Today function returns the current date as a date/time value. The time portion is midnight.

How do you set a date field? ›

On the Insert tab, in the Text group, click Date & Time. In the Date and time dialog box, select the format you want. Select the Update automatically check box. The date is inserted as a field and will update automatically.

What is the main difference between patch and put request? ›

PUT is a technique of altering resources when the client transmits data that revamps the whole resource. PATCH is a technique for transforming the resources when the client transmits partial data that will be updated without changing the whole data.

How do I patch multiple forms in PowerApps? ›

PowerApps Patch multiple forms

To submit Multiple forms we will use the patch function with the forms control. Patch(DataSource,Defaults(DataSource),Form1. Updates,Form2. Updates,Form3.

What is the difference between post put and patch? ›

Here is a simple description of all: POST is always for creating a resource ( does not matter if it was duplicated ) PUT is for checking if resource exists then update, else create new resource. PATCH is always for updating a resource.

Why are updates called patches? ›

Historically, software suppliers distributed patches on paper tape or on punched cards, expecting the recipient to cut out the indicated part of the original tape (or deck), and patch in (hence the name) the replacement segment.

What is patch in deployment? ›

Patch Deployment is a process which involves the deployment of hotfixes/patches that are released from time to time. Patch management is one of the most important tasks in any IT organization.

What is a feature patch? ›

Security patches address known security vulnerabilities, making the software more secure. Feature patches add new functionality to the software. Microsoft, for example, at one time provided Windows feature updates twice per year, adding new capabilities to the Windows 10 operating system.

What is the difference between patch and hotfix? ›

Most products release patches periodically, sometimes as part of its new version releases.
...
Hotfix vs Patch: Core Differences.
HotfixPatch
Often, not tested before release.Typically tested before release.
Released in response to customer reports of one or more bugs disrupting UX.Released as part of a predetermined schedule.
5 more rows
Nov 1, 2022

How do I check for a patch update? ›

Select Start > Settings > Update & Security > Windows Update , and then select Check for updates.

What is patch in application packaging? ›

A patch to a package is just a sparse package designed to overwrite certain files in the original.

Can we use patch for collection Power Apps? ›

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.

What is a patch in electrical? ›

A patch cable, patch cord or patch lead is an electrical or optical cable used to connect ("patch in") one electronic or optical device to another for signal routing. Devices of different types (e.g., a switch connected to a computer, or a switch to a router) are connected with patch cords.

What are the different functions in Power Apps? ›

Substitute – Replaces part of a string with another string, by matching strings. SubmitForm – Saves the item in a form control to the data source. Sum – Calculates the sum of a table expression or a set of arguments. Switch – Matches with a set of values and then evaluates a corresponding formula.

How many types of patches are there? ›

The three most common types of patches are security patches, bug fixes, and feature updates.

What is a patch in image? ›

Image patching provides the ability to select arbitrary shaped regions on an image and replace them with a surface fit to other arbitrary shaped regions, together with an artificial noise component. This is an ideal way to remove unwanted defects from an image for cosmetic reasons.

What is difference between submit and Patch function? ›

With an Edit Form we use the SubmitForm function to save form data back to a SharePoint list. When building a Power Apps Patch Form our own form we must use the Patch function instead to submit data. The Patch function creates a new record or modifies an existing record in a datasource.

What are the 2 main types of connectors used in a patch panel? ›

The network patch panel is typically made with 8-pin modular ports on one side and 110-insulation displacement connector blocks on the other side.

What is difference between patch and update? ›

Patches minimize your attack surface and protect your system against attackers. “While general software updates can include lots of different features, patches are updates that address specific vulnerabilities.”

What is the difference between a patch and a plugin? ›

Plugin = Think of a plugin as hardware (EQ, Reverb, Compressor, etc), that has been turned into software and can be used by your DAW as such. Patch = A patch typically refers to a sound setting in a hardware or software synth. So if you turn on a synth and start scrolling through the built in sounds, those are patches.

Which one is not the function in Power Apps? ›

The Not function returns true if its argument is false; it returns false if its argument is true.

What are the 6 major components of Power Apps? ›

Following are some of the main components in PowerApps.
  • Gallery: A gallery is one way to visualize data within the application. ...
  • Screen: It is a way to view a specific dataset or a record on the screens such as Desktop, iPad, mobile. ...
  • Card: A screen includes cards. ...
  • Control: ...
  • Property: ...
  • Function:

Videos

1. Using Power Apps Patch to Insert and Update (with People Pickers and Choice columns)
(Pragmatic Works)
2. PowerApps patch function examples Part 2
(Power Platform Geeks)
3. Patch vs Update vs UpdateIf in PowerApps (which one to use)
(Alireza Aliabadi)
4. Power Apps Patch Function : Part1
(Power Platform Geeks)
5. Power Platform Solution Patching and Cloning Tutorial
(Pragmatic Works)
6. Power Apps: Use Patch To Create Records Without Forms [Power Platform Series - Ep. 13]
(Pragmatic Works)
Top Articles
Latest Posts
Article information

Author: Terence Hammes MD

Last Updated: 01/27/2023

Views: 6555

Rating: 4.9 / 5 (69 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Terence Hammes MD

Birthday: 1992-04-11

Address: Suite 408 9446 Mercy Mews, West Roxie, CT 04904

Phone: +50312511349175

Job: Product Consulting Liaison

Hobby: Jogging, Motor sports, Nordic skating, Jigsaw puzzles, Bird watching, Nordic skating, Sculpting

Introduction: My name is Terence Hammes MD, I am a inexpensive, energetic, jolly, faithful, cheerful, proud, rich person who loves writing and wants to share my knowledge and understanding with you.