You are currently viewing PowerApps Patch function uses and examples

PowerApps Patch function uses and examples

In this article, we will know what is PowerApps patch function? how to patch a collection PowerApps?, how PowerApps patch new record? how to use the PowerApps Patch function to submit data to multiple lists and many examples.

What is the PowerApps Patch function?

Patch function in PowerApps used to create record in the data source or modify a single or multiple records without affecting other properties.

You can

  •  Use Patch with the Defaults function to create records.
  • Modify one or more records of a data source.
  • Update the records in a data source without affecting other properties.
  • Perform the updates that require no user interaction.
  • Use the ForAll function to update or create multiple records using the Patch function

PowerApps patch function syntax

Usage: Used to modify or create a record in a data source.

Syntax :

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

  • DataSource:  the data source that contains the record you want to create or modify.
  • BaseRecord: the record to modify or create.
  • ChangeRecord(s): One or more records that contain properties to modify in the BaseRecord and processed in order from the beginning of the argument list to the end.

Usage: Used to modify or create a set of records in a data source

Syntax :

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

Usage: Used to merge records, it is required at least two records that you want to merge.

  • DataSource – Required. The data source contains the records that you want to modify or 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 in the BaseRecordTable. Change records are processed in order from the beginning of the argument list to the end, Later property values override earlier ones.

Syntax :

Patch( Record1, Record2 [, …] )


powerapps patch examples

In this examples, we will use powerapps patch function with sharepoint list

PowerApps patch create new record

You can use the Power Apps Patch function with the Defaults function to create a new record in the Data source (The Defaults function is often used inside a Patch ).

  • The Defaults function creates a base record that you can then update with the column values you provide.
  • At least you will provide the values for the required columns and in this case, it will fill the other columns with blank.

This below formula helps you to create new record in the SharePoint list “Employee information”

Patch(‘Employee Information’,Defaults(‘Employee Information’),{FirstName:”Heba”,LastName:”Hamza”,Mobile:0132234567})

PowerApps Patch function

So this is how PowerApps Patch SharePoint List New Item.


PowerApps patch function return value

The return value of Patch function is the record that you modified or created.

In some cases we ask our selves how to get the item id in PowerApps?

You can get the id of the item created using the patch function as the Power Apps Patch function returns the item created.

  • PowerApps patch function returns the item created, then you can store it in a variable and use it for example,.
patch1 | Power Platform Geeks
  • Then get the id of the variable for the item created.
patch3 | Power Platform Geeks

Now we can say that the PowerApps patch function return value is the item created and you can use it to get the details of the item that you just created.


Power Apps patch function multi line field

you can use the Char(10) to add new lines in your text.

patch4 | Power Platform Geeks

PowerApps patch function number field

This formula will helps to patch number field.

Patch(‘Employee Information’,Defaults(‘Employee Information’),{Title:”Patch No”,Mobile:0541232323})

Note that there are no double quotes around the number value.


PowerApps patch function date

Use the Data function to set the field value to any date or you can use the now() function to set the field value to the current time.

This formula will helps to patch Date field.

Patch(‘Employee Information’,Defaults(‘Employee Information’),{Title:”test date”,’date of birth ‘:Date(2021,6,22)})


PowerApps patch function Yes/No column

Yes/no fields have two values” true or false“. To set the fields of the type Yes, simply use true and false values or expressions that give a true or false value.

Patch(‘Employee Information’,Defaults(‘Employee Information’),{Title:”test Yes/no”,isActive: true})


PowerApps patch function choice field

Another PowerApps Patch function example is to patch a record that contains Choice field.

Here I want to update the choice value of a specific item in the SharePoint list.

The Power Apps Formula that patch a choice field expect record type “Id and Value” for the chosen field.

In this scenario i have drop down list that filled withe values from SharePoint list choice field :

Choices([@’Employee Information’].JobTitle)

You can use the Choices function to fill the drop down list with the SharePoint choice field.

Now we want to use PowerApps Patch function to create new record that contain choice field , this below formula helps you to perform this task.

Patch(‘Employee Information’,Defaults(‘Employee Information’),{Title:”test Choice”,’Job Title’:Dropdown1.Selected})

PowerApps patch function choice field
PowerApps patch function choice field

‘Job Title’ is the Choice field that will contain the record that we selected from the drop-down list “Dropdown1.Selected”.

This is how we can use dropdown value in PowerApps patch function.


In general, to patch the Choice field you have to provide the Id and the Value of the field.

Patch(‘Employee Information’,Defaults(‘Employee Information’),{Title:”test Choice”,’Job Title’:{Id:0,Value:”choice1″}})

Job Title the SharePoint Choice column name .

Id the id of the choice ” the item” that the user chose it to begin from 0, 1,2,3,… in sequence ” get it from your item control, for example, BrowseGallery1.Selected.ID” the id comes through a gallery’s Items property.

Value the text value of the Choice “the item”.

PowerApps patch function choice field
PowerApps patch function choice field

This is how to save Choice field value using PowerApps Patch function.


PowerApps patch function with lookup

To use Power apps patch function with lookup, you do the same as we do in choice field. Provide the id and the value for the lookup field.

Patch(‘Employee Information’,Defaults(‘Employee Information’),{Title:”test lookup”,’Office Name’:{Id:Dropdown1_1.Selected.ID,Value:Dropdown1_1.Selected.Title}})

‘Office Name’ the SharePoint lookup column name .

PowerApps patch function lookup field
PowerApps patch function with lookup

Power Apps patch Person Column

This Field type requires you to supply this information [Claims, Email, Department, DisplayName, JobTitle, Picture].

you canuse the Office365Users connector to get the details of the user

{
  Claims: Concatenate(
          "i:0#.f|membership|",
          User().Email 
          ),
          Department: "",
          DisplayName: User().FullName,
          Email: User().Email, 
          JobTitle: "", //the user job title
          Picture: "" // get the user pic
}

PowerApps patch update record

To change one or more records in a data source, use the Patch function. you can change the values of specific fields without affecting other attributes. This formula, for example, modifies the work phone number of an employee with the email “hamza@devoworx.com”:

Patch(‘Employee Information’,Lookup(‘Employee Information’, Email=”hamza@devoworx.com”),{‘Work Phone’:12324})

So this how to use powerapps patch function to update existing record.


Power Apps Patch to modify multiple records

You can use Patch to create or update multiple records in a single call, all that you do is passing a table of base records in the second argument instead of a single base record.

Syntax: PatchDataSourceBaseRecordsTableChangeRecordTable1 [, ChangeRecordTable2, … ] )

The number of records in each changetable must be the same as the number of records in the base table.

The PowerApps patch function return value is a table with each record corresponding one-for-one with the base and changerecords.

PowerApps patch collection

You can use the power Apps patch function to modify or create a set of records in a data source based in 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. So what if you want to bind the data from the collection that have different column names? In this case, we can use the Patch function as the bellow examples

Suppose we have a collection that contains these fields (empname,workphone), and we want to patch these records to a SharePoint list in the columns (Title, ‘Work Phone’).

Create Collection TempCollection in the Onstart property of the app, and don’t forget to click Run OnStart to create the collection.

ClearCollect(TempCollection,{empname:”collection record1″,workphone:1645723},{empname:”collection record2″,workphone:16723})

To use powerapps patch from collection apply this formula

patchcol | Power Platform Geeks
powerapps patch with collection

Conclusion

In this Power Apps post we know the following :

  • What is the power Apps patch function?
  • PowerApps patch function with lookup
  • PowerApps patch function number field
  • PowerApps patch function choice field
  • PowerApps patch function return value
  • PowerApps patch function date field
  • PowerApps patch function to update existing record
  • PowerApps patch function to create existing record
  • PowerApps patch function syntax
See Also
Join us
Need Help
  • Have a related question? Please ask it at deBUG.to Community.

Heba Kamal

Microsoft MVP, MCT, Technical Speaker, Blogger, and Microsoft 365 and Power Platform Consultant.