PowerApps Patch Function with examples

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

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.

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.

patch function in powerapps
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.
patch function in power apps
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 patch function
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’.

Power apps patch function
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 patch function syntax
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 patch function SharePoint list
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 patch function SharePoint list
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: "
patch function in powerapps example
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.

patch function in powerapps examples
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 patch function examples
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 update sharepoint list item on button click
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 patch update sharepoint list item
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.
power apps patch update sharepoint list item
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, that’s 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 Button’s OnSelect property. As you can see, the below formula is having the dropdown value as “Client: Dropdown1.Selected“.

PowerApps Patch Sharepoint List New Item
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.

power apps patch function create new record
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 patch function create new record
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 patch function to get item id
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

Power Apps patch function to get item id
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.

get item id in Power Apps patch function
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.

get item id in PowerApps patch function
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 patch function create new record

Let’s 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 patch function create a new record
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 patch create new record
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.
Create new record using PowerApps Patch Function
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.
Save Choice field value using PowerApps Patch function
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.

Save Choice field value in PowerApps Patch function
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.
Save Choice field in PowerApps Patch function
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 patch function with lookup
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 patch with lookup
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 patch function lookup
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 patch function using lookup
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 Button’s 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 patch function return value
  • 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 patch function return values

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.
  • Let’s 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 patch function using dropdown value
  • 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 patch function dropdown value
  • 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 patch function dropdown values
  • 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 patch using dropdown value
  • Now go back to the SharePoint list (Project Details). You can view the Client value of Bijay as shown in the below screenshot.
PowerApps patch using dropdown values

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

Also, you may like these below Powerapps Tutorials:

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
>