PowerApps add item to SharePoint list Patch

PowerApps add item to SharePoint list Patch

In this PowerApps tutorial, We will discuss what is Patch function in Powerapps and what is the syntax for Powerapps Patch function.

Complete SharePoint Training Course Bundle Just for $199

Also, We will see these below things as:

  • PowerApps patch function SharePoint list
  • How to update SharePoint List Item on button click in PowerApps
  • PowerApps Patch SharePoint List New Item
  • Get item id using PowerApps patch function
  • PowerApps patch collection
  • PowerApps patch function create new record
  • Save Choice field value using PowerApps Patch function
  • PowerApps patch function with lookup
  • PowerApps patch function return value
  • PowerApps patch function dropdown value

By taking a simple scenario, We will see where you can use this Patch function in PowerApps.

Patch function in PowerApps

PowerApps Patch Function is used to modify single or multiple records of a data source. In the other sense, PowerApps Patch function is used to update the records in a data source without affecting other properties.

This means it will only update the field value that you have specified in the formula.

PowerApps Patch Function Syntax

  • This below is a simple Powerapps patch function syntax which helps to change the phone number for an employee named Bijay. It will only update the specific field value from the Employees data source.
Patch( Employees, First( Filter( Employees, Name = "Bijay" ) ), { Phone: "675-849-8401" } )
  • Similarly, you can use the Patch with the Defaults function to create a record in the Data source. This below formula helps to create a record for an employee named Preeti.
Patch( Employees, Defaults( Employees ), { Name: "Preeti" } )
  • Suppose you are not using any data source and you want to use Patch to merge two or more records, then in this case also, you can use the PowerApps Patch function.
  • Below represents a formula that helps to merge two records into one that identifies both the Phone number and the Department for a specific Employee.
Patch( { Name: "Bijay", Phone: "675-849-8401" }, { Name: "Bijay", Department: "IT" } )

Modify or create a single record in a data source

Below represents the PowerApps Patch Function syntax which helps to modify or create a single record in the data source.

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

Where,

  • DataSource: Specify the data source that contains the record that you want to modify or it will contain the record that you want to create.
  • BaseRecord: 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): 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

Below represents the PowerApps Patch Function syntax which helps to modify or create multiple records in data source.

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

Where,

  • DataSource: Specify the data source that contains the record that you want to modify or it will contain the record that you want to create.
  • BaseRecord: The 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): 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.

Read: Power Apps Button OnSelect

PowerApps patch function SharePoint list

Scenario:

I have a SharePoint Online list named Project Details. This list has below columns with different data types as:

  • Title (Bydeafult Single line of text)
  • Employee First Name (Single line of text)
  • Employee Last Name (Single line of text)
  • Client (Choice/Dropdown)
  • Client Project (Single line of text)

Also, you can see this SharePoint list is having some records as shown in the below screenshot.

In my scenario, I want to patch or update a specific record in the SharePoint list using the Powerapps Patch function.

PowerApps add item to SharePoint list Patch
SharePoint Online List

Create PowerApps Canvas App and use Patch Function

Follow these below things:

  • Open the PowerApps page through the Browser. Sign in your PowerApps using Microsoft account.
  • In the Power Apps page, Select + New app -> Canvas. Choose Tablet or Phone layout under the Blank app section.
  • Then a PowerApps page (with tablet layout) will appear with the new blank screen.
  • Insert a Vertical Gallery control (Insert -> Gallery -> Vertical). Connect the new or existing SharePoint Data source to the vertical gallery control as shown below.
PowerApps add item to SharePoint list Patch
PowerApps SharePoint data source
  • Select the Vertical Gallery control and Go to the Properties pane (from the right side of the page).
  • Select the Data source as SharePoint List (Project Details) and also change the Layout as Title.
  • Click on Edit from the Fields section and select the Title field as Employee First Name. Then you can see the gallery will appear with only the Employee Name.
PowerApps add item to SharePoint list Patch
powerapps patch function
  • Resize the gallery or expand the gallery as of the screen size and delete the navigate icon (>) from it.
  • Expand the Title Data card from downwards and apply the below formula on its Text property as:
Text = ThisItem.'Employee First Name' & " " & ThisItem.'Employee Last Name'

Where,

Employee First Name and Employee Last Name = SharePoint List Column Name

This above formula is the combination of the Employee First Name and Employee Last Name. If you want to display only Employee First Name, then no need to combine with the Employee Last Name. Simply, you can write as ThisItem.Employee First Name.

PowerApps add item to SharePoint list Patch
powerapps patch function example
  • Under the Title data card, Insert a Label and apply the below text on its Text property as:
Text = "Client: "
PowerApps add item to SharePoint list Patch
powerapps patch function
  • Add a Dropdown control (Insert -> Input -> Dropdown) and apply the below formula on its Items properties as:
Items = Choices('Project Details'.Client)

As the Client field is a choice column, so I have written this above formula to get all the choices.

PowerApps add item to SharePoint list Patch
Patch function in PowerApps
  • When you will preview, you can see the dropdown control (Client) is having all the choices from the SharePoint list (Project Details).
PowerApps add item to SharePoint list Patch
PowerApps patch function SharePoint list
  • Similarly, again add a Label below the Client dropdown and apply the below formula on its Text property as:
Text = "Client Project: "
PowerApps add item to SharePoint list Patch
PowerApps update SharePoint Online List Item
  • Add a Text input control and apply the below formula on its Default property as:
Default = ThisItem.'Client Project'

As the Client Project field is a text column, so I have written this above formula to get all the projects of each record.

PowerApps add item to SharePoint list Patch
PowerApps update SharePoint Online List Item
  • Now change the Default property of Dropdown control (Client) as:
Default = ThisItem.Client.Value

This above formula helps to get all the default value of each record as shown below.

PowerApps add item to SharePoint list Patch
PowerApps update SharePoint List Item

PowerApps update SharePoint List Item on button click

Now if you will preview the app, then you can see there will be nothing happen if you will select any client dropdown and as well as the Client project.

To perform some action for this, We will add a Button that will help you to update and save the record in the SharePoint List (Project Details). For powerapps patch function to update the record, follow these below things :

  • Select the gallery control, Insert a Button (Insert -> Button) and just rename it to Save as shown below.
  • Select the Button and apply this below formula on its OnSelect property as:
OnSelect = Patch('Project Details',ThisItem,{Client: DropdownClient.Selected, ClientProject: txtClientProject.Text})

Where,

  • DropdownClient = It is the Client dropdown control name. As it is a Dropdown control, so this specifies as DropdownClient.Selected.
  • txtClientProject = It is the Client Project Text control name. As it is a Text input control, so this specifies as txtClientProject.Text.
PowerApps add item to SharePoint list Patch
PowerApps update SharePoint List Item on button click
  • Preview the Powerapps app and modify the Client and Client Project of a specific record. Then Save it as shown in the below screenshot.
PowerApps add item to SharePoint list Patch
PowerApps update SharePoint List Item on button click example
  • Now go to the SharePoint list (Project Details). Check the specific record that you have modified and saved in the app. You will see the record will be updated in the SharePoint list itself.
PowerApps add item to SharePoint list Patch
PowerApps update SharePoint List Item on button click

PowerApps Patch SharePoint List New Item

PowerApps Patch function not only helps to update the record of a specific Data source but also helps to create a new record in the Data source.

Here, We will see how to create a new record in the SharePoint List using Powerapps patch function.

  • Insert a Button (Insert -> Button) on the Powerapps screen and rename it to Create a New Item in SharePoint List. Apply the below formula on its OnSelect property as:
OnSelect = Patch('Project Details', Defaults('Project Details'), {Title: "Project-6", 'Employee First Name': "Soumya", 'Employee Last Name': "Agarwal", Client: Dropdown1.Selected, 'Client Project':"SPFx"})

Where,

  • Project Details = Specify the SharePoint Data source where you want to create the new record.
  • Defaults(Project Details) = It will help you to create a new record in the SharePoint List.
  • Title, Employee First Name, Employee Last Name, and so on = All are the SharePoint List Column Name. You need to specify the values for each field. So that the new record will store in the SharePoint list.

You can see in the below screenshot, there is a Dropdown control besides the Button. Since I have a choice column (Client) in my SharePoint list, thats why I have taken a Dropdown control and applied this below formula on its Items property as:

Items = Choices('Project Details'.Client)

So what it is exactly doing is, It will take the selected dropdown value in the Buttons OnSelect property. As you can see, the below formula is having the dropdown value as Client: Dropdown1.Selected.

PowerApps add item to SharePoint list Patch
PowerApps Patch SharePoint List New Item

Now preview the app and select one Client choice from the dropdown control. Then click on the Button (Create a New Item in SharePoint List) as shown below.

PowerApps add item to SharePoint list Patch
PowerApps Patch SharePoint List New Item

Go back to the SharePoint List (Project Details). You can see the new item has been created as the below screenshot.

PowerApps add item to SharePoint list Patch
Create a new record in the SharePoint List using PowerApps patch function

Powerapps patch function to get item id

Suppose at the time of creating a new item in the SharePoint list, you want to get the Id of that item.

To get the item id using Powerapps patch function, you need to take a Button (Create a New item and Get Item ID) and set a Variable on its OnSelect property as:

OnSelect = Set(ItemID, Patch('Project Details', Defaults('Project Details'), {Title: "Project-7", 'Employee First Name': "Dinesh", 'Employee Last Name': "Bharadwaj", Client: Dropdown1.Selected, 'Client Project':"SPFx"}))

The formula is almost similar to the above one (PowerApps Patch Sharepoint List New Item). Only the difference is, you need to set one variable (ItemID) that will help you to get the id of that item.

PowerApps add item to SharePoint list Patch
Powerapps patch function to get item id

Take one Label (Insert -> Label) and set the variable (ItemID) on its Text property as:

Text = ItemID.ID

Where,

ItemID = Variable name

PowerApps add item to SharePoint list Patch
Powerapps patch function to get item id

Preview the app and click on the button (Create a New item and Get Item ID) to create a new item in the SharePoint List. At the same time, in the label, you can see the ID of that created item as shown below.

PowerApps add item to SharePoint list Patch
Powerapps patch function to get item id example

Also, If you will check in the SharePoint list, you can see the same ID of the newly created item.

PowerApps add item to SharePoint list Patch
get item id in PowerApps patch function

Powerapps patch collection

You can refer this below link to learn more details about the Powerapps Patch Collection:

  • PowerApps Collection: Add, Update, Remove and Filter items

PowerApps patch function create new record

Lets using the PowerApps app, you want to create a new record or item in a SharePoint list. Then, in this case, you can use the PowerApps Patch function. Follow the below steps to create a new item in the SharePoint list.

  • There is a SharePoint list named MarkSheet i.e. having different types of columns as shown below. Also, it is having some different records of each student. Here I want to create a new record using the PowerApps Patch function.
PowerApps add item to SharePoint list Patch
PowerApps patch function create new record
  • To do so, On the PowerApps screen, insert a PowerApps Button input and rename it to Click to Create. Select the button and apply this below formula on its OnSelect property as:
OnSelect = Patch( MarkSheet, Defaults(MarkSheet), { Title: "Aditya", Accountancy: 55, English: 45, Maths: 44, Economics: 62 } );

Where,

  1. MarkSheet = SharePoint list name
  2. Title, Accountancy, English, Maths, Economics = These are the SharePoint column names
PowerApps add item to SharePoint list Patch
PowerApps patch function create a new record
  • Next Save and Preview (F5) the app. Press the Button (Click to Create) and go to the specific SharePoint list (MarkSheet). Once you will refresh the list, you can see the new item has been created as the below screenshot.
PowerApps add item to SharePoint list Patch
create a new record using PowerApps Patch function

Save Choice field value using PowerApps Patch function

Suppose you want to save the choice field value in the SharePoint list using the PowerApps Patch function, then follow this below steps.

  • Below represents a SharePoint list named MarkSheet. This list has a Choice column named Status (Pass and Fail). Also, it has some records as like the below screenshot.
  • In this scenario, I want to patch the Status column in the SharePoint list (MarkSheet) using the PowerApps patch function.
PowerApps add item to SharePoint list Patch
Save Choice field value using PowerApps Patch function
  • To do this, select the Button input (Hit me!) and put this below formula on its OnSelect property as:
OnSelect = Patch( MarkSheet, Defaults(MarkSheet), { Title: "Preeti", Accountancy: 65, English: 75, Maths: 84, Economics: 92, Status: { '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", Id: ItemID, Value: "Pass" } } )

Where,

  1. MarkSheet = SharePoint list name
  2. Title, Accountancy, English, Maths, Economics = These are the SharePoint column names
  3. Status = This is the SharePoint Choice column
  4. @odata.type = This is a predefined column. You just need to copy and paste this full line as [@odata.type:#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference]

You can refer to this below screenshot.

PowerApps add item to SharePoint list Patch
Save Choice field value using PowerApps Patch function
  • Now Save and Preview (F5) the app. Press the Powerapps Button (Hit me!). Go to the specific SharePoint list (MarkSheet) and refresh the list.
  • Once you will refresh the list, you can see the created item or record has been updated with the specified Status value as shown in the below screenshot.
PowerApps add item to SharePoint list Patch
How to Save Choice field value using PowerApps Patch function

PowerApps patch function with lookup

In this scenario, We will see how to work with PowerApps Patch Function with Lookup (from SharePoint list).

  • Below represents a SharePoint list named StudentID. This list has a column named Student ID (Number Datatype) that is having all individual student IDs.
PowerApps add item to SharePoint list Patch
PowerApps patch function with lookup
  • The below represents another SharePoint list named MarkSheet i.e. having different types of columns with a Lookup column i.e. StudentID (from the StudentID list).
  • In the MarkSheet list, there are different records of each student as shown in the below screenshot.
  • Now what I want to do is, I want to view the ID of a specific student that will retrieve from the Student ID list and the result will display in the lookup column (in the MarkSheet list).
PowerApps add item to SharePoint list Patch
PowerApps patch function with lookup
  • On the PowerApps Screen, I have a Gallery control that displays all the student records. When I will select a specific record from the gallery and click on the button, then the ID will retrieve from the StudentID list and it will display in the MarkSheet list.
  • For that, Select the Button input (Hit me) and apply this below formula on its OnSelect property as:
OnSelect = Patch( MarkSheet, Defaults(MarkSheet), { Title: Gallery2.Selected.Title, StudentID: { '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", Id: Gallery2.Selected.ID, Value: Gallery2.Selected.Name } } )

Where,

  1. MarkSheet = SharePoint list name
  2. Title = This is the SharePoint column (By default) from the Marksheet list
  3. Gallery2 = PowerApps Gallery control name
  4. @odata.type = This is a predefined column. You just need to copy and paste this full line as [@odata.type:#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference]

NOTE:

one important thing you should note that, please change the lookup field display value to @odata.type to check if this value matches the one defined under the SharePoint list you created.

Refer to the below screenshot.

PowerApps add item to SharePoint list Patch
PowerApps patch function with lookup column
  • Next, Save and Preview the app. Select a specific item from the gallery control and hit on the button. Then come to the SharePoint list (MarkSheet).
  • Once you will refresh the list, you can see the specific look-up ID has been retrieved from the other list as shown below.
PowerApps add item to SharePoint list Patch
PowerApps patch function with lookup example

This is how the PowerApps patch function with lookup works.

PowerApps patch function return value

In this example we will see how we can access the returened value from the PowerApps Patch function.

  • Here I can say that 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.
  • But here one question comes to your mind is, How do we access this value? As simple, what I want to do is, when an item is created in SharePoint it is given an auto-generated ID. As we are looking to access the returned value/record so we can use the given ID within the app without having to re-query the data source.
  • Suppose you want to view specific item details with the ID. Then apply this below formula on Buttons OnSelect property as:
OnSelect = ClearCollect( MyPatchedItems, Patch( MarkSheet, Defaults(MarkSheet), { Title: "Isha", Maths: 30 } ) )

Where,

  1. MyPatchedItems = Collection name where the value will return
  2. MarkSheet = SharePoint list name
PowerApps add item to SharePoint list Patch
  • Now Save and Preview the app. Go to the specific PowerApps Collection. You can view the returned value of that specific item as shown in the below screenshot.
PowerApps add item to SharePoint list Patch

PowerApps patch function dropdown value

In this scenario we will see how to use a Dropdown value in the PowerApps Patch function.

  • The below screenshot represents a SharePoint list named Project Details. This list has different types of columns including a Choice column (Client).
  • As per my requirement, By using the PowerApps Patch function, I want to update the choice value of a specific item in the SharePoint list.
  • Lets do it. There is an Item title called Power BI Project and employee name as Bijay. I want to update only the choice value of the Client column of this specific item. That means, now it is an HCL client, but I want to update it to Dynamic Systems.
PowerApps add item to SharePoint list Patch
  • On the PowerApps screen, Insert a Dropdown control and set its Items property to this below formula as:
Items = Choices([@'Project Details'].Client )

Where,

  1. Project Details = SharePoint list name
  2. Client = Its a choice column of that specific list
PowerApps add item to SharePoint list Patch
  • Now insert a Button input and rename it to Update. Apply this below formula on its OnSelect property as:
OnSelect = Patch( 'Project Details', First( Filter( 'Project Details', 'Employee First Name' = "Bijay" ) ), {Client: Dropdown2.Selected} )

Where,

  1. Project Details = SharePoint list name
  2. Employee First Name = This is one of the columns from the specified SharePoint list. Mention a name whose record you want to update
  3. Client = SharePoint choice column name that you want to update
  4. Dropdown2 = Dropdown control name
PowerApps add item to SharePoint list Patch
  • Save and Preview (F5) the app. Select one of the choice values from the dropdown control that you want to update and click on the button (Update).
PowerApps add item to SharePoint list Patch
  • Now go back to the SharePoint list (Project Details). You can view the Client value of Bijay as shown in the below screenshot.
PowerApps add item to SharePoint list Patch

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

Also, you may like these below Powerapps Tutorials:

  • PowerApps set field value based on another field
  • Embed PowerApps in SharePoint modern page
  • Show hide fields based on dropdown selection PowerApps
  • How to use date time picker in PowerApps
  • PowerApps toggle control + How to use with example
  • The function Search has some invalid arguments in PowerApps
  • PowerApps Search Function + How to use with example
  • PowerApps Timer Control: How to use + start and reset with button
  • Create People Picker in Power Apps with Combo Box
  • How to Create PowerApps GridView
  • PowerApps Combobox Control
  • PowerApps Lower, Upper, and Proper function

In this PowerApps Tutorial, we learned what is Powerapps Patch function and what is the syntax of Powerapps Patch function.

Also, We covered these below things as:

  • PowerApps patch function SharePoint list
  • How to update SharePoint List Item on button click in Powerapps
  • PowerApps Patch Sharepoint List New Item
  • Get item id using Powerapps patch function
  • Powerapps patch collection
  • PowerApps patch function create a new record
  • Save Choice field value using PowerApps Patch function
  • PowerApps patch function with lookup
  • PowerApps patch function return value
  • PowerApps patch function dropdown value

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site EnjoySharePoint.com