8 Various Ways to Use The Patch Function in Power Apps

Recently, I worked on the Power Apps Patch function to create and update single or multiple records in a data source (SharePoint List). So, I thought I would share all the Power Apps Patch concepts in this post.

In this Power Apps tutorial, I will explain the Patch function in PowerApps, Patch syntax in PowerApps, and Patch PowerApps SharePoint list.

Moreover, we will discuss different ways to use the patch function in PowerApps example. Such as:

  • Create or modify a single record in a data source
  • Create or modify multiple records in a data source
  • How to merge multiple records outside of a data source
  • Patch Power Apps SharePoint List using Different Controls
  • Patch Filter Power Apps
  • Power Apps patch dropdown value

Patch Function in Power Apps

In Power Apps, the Patch function is a powerful tool for modifying or creating records in a data source without affecting other properties.

It allows you to update and insert records in a data source such as a SharePoint list or SQL Server table. This means it will only update the field value that you have specified in the formula.

Patch Function Syntax in Power Apps

Next, follow the below Power Apps Patch function syntaxes. Such as:

Syntax-1: [For Single Record]

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 containing 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.

Syntax-2: [For Multiple Records]

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

Where,

  • 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 once

Patch Power Apps SharePoint List

let’s see how to work with the patch Power Apps SharePoint list using different ways. Such as:

Create a Single Record in Data Source Using Power Apps Patch

To create a single record in a SharePoint list using a Patch function, follow the below example.

Input:

I have a SharePoint list named “Diseases List” which contains the below fields.

Column NameData Type
DiseaseSingle line of text column
Doctor’s NameSingle line of text column
Doctor’s FeesNumber
Doctor’s ExperienceNumber
patch function in powerapps

Now, I would like to use the Patch function to create or add a new record from the Power Apps to the SharePoint list.

For that, insert a Button control [Patch New Record] on the Power Apps Screen and set its OnSelect property to the code below.

OnSelect = Patch(
    'Diseases List',
    Defaults('Diseases List'),
    {
        Disease: "polio",
        'Doctor''s Name': "Lynee",
        'Doctor''s Fees': 2000,
        'Doctor''s Experience': 4
    }
)

Where,

  • ‘Diseases List’ = SharePoint Online list
  • Disease, Doctor’s Name, etc. = SharePoint list fields
patch function in powerapps example

Once your updates are done, Save, Publish, and Preview the app. When the user clicks on the button control, the new record details are submitted on the SharePoint list, as shown below.

Output:

patch syntax in powerapps

Modify or Update a Single Record in Data Source Using Power Apps Patch

Now, I will show you how to update a single record in the SharePoint list using the Patch function. To do so, follow the below steps.

1. On the Power Apps Screen -> Insert a Button control and set its OnSelect property as:

OnSelect = Patch(
    'Diseases List',
    LookUp(
        'Diseases List',
        ID = 1
    ),
    {
        'Doctor''s Fees': 2500,
        'Doctor''s Experience': 5
    }
)
patch function syntax in powerapps

2. Once you click on the button control, the specific SharePoint list item will be updated successfully, as shown below.

Output:

patch powerapps sharepoint list

Create Multiple Records in Data Source Using Power Apps Patch

In this example, we will see how to create multiple records in the SharePoint list using the patch function. To achieve it, follow the below steps.

1. On the Power Apps Screen, insert a Button control and set its OnSelect property to the code below.

OnSelect = ClearCollect(
    colNewDiseases,
    Table(
        'Diseases List'@{
            Disease: "Cancer",
            'Doctor''s Name': "Johannal",
            'Doctor''s Fees': 4000,
            'Doctor''s Experience': 4
        },
        'Diseases List'@{
            Disease: "Diabetes",
            'Doctor''s Name': "Patti",
            'Doctor''s Fees': 3500,
            'Doctor''s Experience': 3
        }
    )
);
Patch(
    'Diseases List',
    ForAll(
        Sequence(CountRows(colNewDiseases)),
        Defaults('Diseases List')

Where,

  • colNewDiseases = Power Apps collection name
powerapps patch sharepoint list

2. Once your app is ready, Preview the app. When the user clicks on the button control, created two records will be saved in the SharePoint Online list.

Output:

patch formula in powerapps

Modify Multiple Records in Data Source Using Power Apps Patch

Similarly, if you want to modify or update multiple records in a Sharepoint list using the patch function, follow the below-mentioned steps. Such as:

1. On the Power Apps Screen, insert a Button control and set its OnSelect property to the code below.

OnSelect = colUpdateDiseases,
    Table(
        'Diseases List'@{
         ID: 4,
        'Doctor''s Fees': 3000,
        'Doctor''s Experience': 4     
            
        },
       'Diseases List'@{
        ID:10,
        'Doctor''s Experience': 3
        }
    )
);
Patch(
    'Diseases List',
    colUpdateDiseases
);
patch sharepoint list powerapps

2. Now, click on the button control to update multiple records in the SharePoint list at a time, as shown below.

patch power apps sharepoint list

This is how we can update or create a single or multiple records in the SharePoint list using the Patch function.

Merge Multiple Records Outside of a Data Source Using Power Apps Patch

In this section, I will show you how to merge multiple records outside of a data source with a simple example.

Example:

On the Power Apps Screen -> Insert a Modern Button control and set its OnSelect property to the code below.

OnSelect = Set(
    varRecord,
    Patch(
        {
            Name: "Johannal",
            Phone: "675-849-8401"
        },
        {
            Name: "Johannal",
            Department: "IT"
        }
    )
)

Where,

  • varRecord = Power Apps variable name
  • Name, Phone, and Department = Table fields
patch syntax powerapps

Finally, click on the button control to get the created records on the variable [varRecord]. To view the created records, go to the Variables section, expand the Global Variables dropdown, and select the create variable record.

Output:

patch powerapps examples

Patch Power Apps SharePoint List Using Different Controls

To create a new SharePoint list record using different controls, follow the example below.

Example:

I have a SharePoint list named “Employee Details” which contains the below fields.

Column NameData Type
Employee NameIt is a default single line of text
Phone NumberNumber
DepartmentA single line of text
powerapps patch function sharepoint list

In Power Apps, there are three Modern Text labels with respective Text input controls and a Button control.

Whenever the user provides the new employee record and clicks on the button control, the new record details will be submitted to the Sharepoint Online list.

To work around this, follow the below steps.

1. On the Power Apps Screen -> Insert three Text input controls and set their Default property as blank.

2. Next, insert a Button control and set its OnSelect property to the code below.

OnSlect = Patch(
    'Employee Details',
    Defaults('Employee Details'),
    {
        Title: txt_EmployeeName.Value,
        'Phone Number': txt_EmployeePhoneNumber.Value,
        Department: txt_EmployeeDepartment.Value
    }
)

Where,

  • Employee Details‘ = SharePoint Online list
  • Title, Phone Number, Department = SharePoint list fields
  • txt_EmployeeName, txt_EmployeePhoneNumber, txt_EmployeeDepartment = Power Apps text input control names
patch function powerapps sharepoint list

3. Once your app is ready, Save, Publish, and Preview the app. Whenever the user provides a new employee record details and clicks on the button control, the new record will be submitted on the SharePoint list.

Have a look at the below s screenshot for the output.

powerapps update sharepoint list item on button click

Patch Filter Power Apps

Suppose you want to update the SharePoint list record using the Power Apps patch filter; follow the below steps.

1. On the Power Apps Screen -> Insert a Button control and set its Onselect property as:

OnSelect = Patch(
    'Employee Details',
    First(
        Filter(
            'Employee Details',
            Title = "Lynee"
        )
    ),
    {'Phone Number': "675-849-8401"}
)
Patch Filter Power Apps

2. Now, go to the Preview section and click on the button control to update or modify the specific SharePoint list records based on the patch filter, as shown below.

Output:

power apps patch function sharepoint list

This way, we can update an existing SharePoint list record using the Power Apps patch filter.

Power Apps Patch Dropdown Value

In the last section, I will show you how to update the existing record on the SharePoint list using the patch dropdown value. To do so, follow the below steps.

1. On the Power Apps Screen -> Insert a Dropdown control and set its Items property to the code below.

Items = ["IT", "Sales", "Finance","HR", "Marketing"]
powerapps patch dropdown value

2. Next, insert a Button control and set its Onselect property as:

OnSelect = Patch(
    'Employee Details',
    First(
        Filter(
            'Employee Details',
            Title = "Lynee"
        )
    ),
    {Department: drp_Departments.Selected.Value}
)

Where,

  • drp_Departments = Power Apps dropdown control name
power apps patch dropdown value

3. Finally, Preview the app. When the user selects the dropdown value and clicks on the update button, the specific Sharepoint list record will be updated, as in the screenshot below.

This is how we can work with the Power Apps patch dropdown value.

patch function to update sharepoint list

I hope this tutorial is useful. This Power Apps tutorial taught in detail, information about how to use the Power Apps Patch function in different ways with real-time scenarios.

Also, you may like some more Power Apps articles:

Moreover, we discussed how to use patch PowerApps SharePoint list, patch function syntax in PowerApps, patch formula in PowerApps, PowerApps patch SharePoint list with single record, Patch SharePoint list PowerApps with multiple records, Power Apps patch SharePoint list using different controls, and many more.

  • Como puedo validar que dos usuarios no actualice el mismo registro. Se puede validar con la funcion pathc (How can I validate that two users do not update the same record. It can be validated with the pathc function)

  • Which Patch item would we use in PowerApps, if we wanted to update a SharePoint list column and keep the prior data.

  • Can you give example for save patch data when 1 click save to save all data you updated? i have a problem with save using 1 button to update data patch for my gallery form sharepoint

  • >