Power Apps Gallery Patch [With Various Examples]

In this Power Apps Tutorial, we will learn about Patch() and how to use it in the Power Apps gallery with various scenarios. We are also going to cover the following topics in this tutorial:

  • What is Patch() in Power Apps?
  • Power Apps Patch() syntax
  • Power Apps patch gallery to SharePoint
  • Power Apps patch gallery updates an existing item
  • Power Apps patch function to get item id
  • Power Apps gallery patch all items
  • Power Apps reset gallery after patch
  • Power Apps gallery Reset inputs fields after patch
  • Power Apps gallery patch selected item
  • Power Apps patch gallery dropdown
  • Power Apps patch gallery date
  • Power Apps patch collections to gallery
  • Power Apps patch gallery Number
  • Power Apps patch gallery person Field
  • powerapps patch gallery check box or patch thisitem

What is Patch() in Power Apps?

Before we begin working with Patch() in the Power Apps gallery, we must first understand what Patch() is and how it is used.

  • Power Apps Patch function is used to create or modify a single record or a list of records within the data source.
  • This enables you to alter the values of fields without affecting other properties. The patch has the ability to save data from multiple screens at the same time.
  • When dealing with complex types Power Apps Patch is extremely beneficial.
  • Also, if you want to update or create multiple records using the Power Apps Patch function, you must use the ForAll function in Power Apps.
  • To use the Power Apps Patch function, you must first create a base record with default values using the Defaults function.

Also Read: Power Apps Gallery Filter [With Real Examples]

Power Apps Patch() syntax

Now we will see what the syntax is and how to use the Power Apps patch functions in different scenarios such as:

  1. To create a new record within the data source using the Power Apps patch function, the syntax will be:
Patch(<Datasource>, BaseRecord, NewRecord)

Where,

  • DataSource: the name of the data source that contains the record you want to create or modify.
  • BaseRecord: The specified record that will be created.
  • NewRecord: Specify the new records with values that will be created in the data source.

2. To modify an existing record within the data source using the Power Apps with Patch function, the syntax will be:

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

Where ChangeRecord(s) are the one or more records that hold properties to modify in the BaseRecord and are processed in the order of the argument list.

3. To modify or add multiple records within the data source, the following Power Apps patch function will be:

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

Where ChangeRecordTable(s) are the one or more record tables containing properties to modify for each record in the BaseRecordTable. Modify records are processed in the order they appear in the argument list, with later property values overriding earlier ones.

4. To change the values of a record variable within the data source, the following syntax of the Power Apps patch function will be:

Patch(<Record1>, <Record2>)

5. To get the record that is modified or created within the data source, the patch syntax will be:

Set(VariableName, Patch(<Datasource>, BaseRecord, ChangeRecord))

Check: Power Apps Data Table [Complete Guide]

Power Apps patch gallery to SharePoint

Here, we will see how to use the patch function from the Power Apps gallery on SharePoint. Before that, we need to prepare a SharePoint list and build a PowerApps gallery using that list.

Also, we will insert a button into the app so that when the user clicks on the button, it will create a new item in the SharePoint list.

So we have prepared a SharePoint list named ‘Vehicles‘ having some columns such as:

ColumnsTypes
Title Default
Regd NumberA single line of text
WheelsNumber
ColorA single line of text
CountryA single line of text
StateA single line of text
OwnerA single line of text
DateDate and Time
powerapps patch gallery to sharepoint
powerapps patch gallery to SharePoint

To build a gallery on the Power Apps, the following steps are:

  • Sign in to the Power Apps with your Office 365 ID or Microsoft user ID.
  • Then it will open the Home page of the Power Apps.
  • Go to Create (On the left panel) > Blank app > Blank canvas app > Create.
  • Give a name to the app and choose a format i.e., tablet or mobile.
  • Click on Create.

We can see it will create an app with a blank screen where we will use the gallery to show the data source.

Example of create a blank canvas app on Power Apps
Example of creating a blank canvas app on Power Apps

To connect the app with the data source, the following steps are:

  • Go to Data (on the left side nav panel).
  • Click on “+Add data.”
  • Select your data source, i.e., search for SharePoint in the search bar.
  • Choose your connection.
  • Choose your SharePoint site.
  • Check the SharePoint list, i.e., Vehicles, and click on Connect.

We can see the data source is connected to the Power Apps. To check this, go to the Data section and find the data source.

Connect data source to the Power Apps
Connect data source to the Power Apps

Let’s use this data source in a gallery. To do this, the following steps are:

  • Go to the Insert tab > Gallery.
  • Select Blank vertical gallery.
  • Choose the data source.
  • Click on Layout (on the right side properties panel) > choose a layout as per your choice to show the data like below:
powerapps patch gallery to sharepoint list
powerapps patch gallery to SharePoint list

The Power Apps will now have a button control. When the button is pressed, a new item is created on the specified data source.

To add the button control, go to the Insert tab > Button. Rename the button as Create Item.

powerapps gallery patch to sharepoint list
powerapps gallery patch to SharePoint list

On the button’s OnSelect property insert the below expression to create a new item inside the SharePoint list.

OnSelect = Patch(Vehicles,Defaults(Vehicles),{Title:"Royal enfield",'Regd Number':"RE2002",Wheels:4,Color:"Matt Black", Country:"UK",State:"Scotland",Owner:"Marrie",Date:Date(2022,8,23)})

Where,

  • Vehicles – The name of the data source
  • Title, Regd Number, Wheels, Color, Country, State, Owner, Date – The name of the SharePoint list columns.
powerapps patch gallery to list
powerapps patch gallery to list

That’s it! Let’s save, publish, and play the app in preview mode. We can see a new item has been created once the button is clicked on the app.

patch Power Apps gallery to Share Point list
patch Power Apps gallery to Share Point list

Also, we can see that a new item has been created in the SharePoint list too.

Create Sharepoint list item from Powerapps gallery using Patch
Create Sharepoint list item from Powerapps gallery using Patch

This is how to create a new SharePoint list item from Power Apps using a patch.

Also, Read: Power Apps Radio Button

Power Apps patch gallery updates an existing item

Here, we will see how to update a gallery item using the patch function. We are going to use the above Power Apps gallery to implement this requirement.

Suppose, we want to update the item that we have created recently. To do this, insert the below expression within the button’s OnSelect property.

OnSelect = Patch(Vehicles,LookUp(Vehicles, ID = 16),{'Regd Number':"RE2020",Wheels:2})

Where,

  • Vehicles – The name of the data source.
  • ID – The name of the prebuilt column of the SharePoint list.
  • Regd Number, Wheels – The SharePoint column names that we want to modify.
Update An Existing item Using Power Apps Patch Function
Update An Existing item Using the Power Apps Patch Function

Save, publish, and play the app now. When we clicked on the button, we saw that the item had been modified.

Update gallery item using Power Apps patch
Update gallery item using Power Apps patch

This is how to update a gallery item using the Power Apps Patch function.

Check out: PowerApps stuck on getting your data

Power Apps gallery patch get the item ID

In this section, we’ll look at how to get the item ID from the Power Apps gallery using the Patch function. When the user inserts any data into the gallery, it will create a new item in the SharePoint list and the user can retrieve the ID of that new item.

We have prepared another SharePoint list named “Voters list” which has columns such as Title, Address, and Age.

power apps gallery patch get id
power apps gallery patch get id

Using the above SharePoint list, we have to build a Power Apps gallery where we have inserted 3 text inputs to insert the Title, Age, and Address respectively. Again, add a label control to show the ID of the created item and a button control to create an item within the gallery.

Powerapps gallery patch function to get item id
Powerapps gallery patch function to get item id

To create the new item dynamically within the gallery, we need to insert the below expression within the button’s OnSelect control. So that it will create a new item within the Power Apps gallery.

OnSelect = Set(VarID, Patch('Voters list',Defaults('Voters list'),{Title:'Title TxtInput'.Text,Age:Value('Age TxtInput'.Text),Address:'Address TxtInput'.Text}))

Where,

  • VarID-The name of the variable
  • Voters list-The name of the data source
  • Title, Age, and Address-The name of the Sharepoint column
  • Title TxtInput, Age TxtInput, Address TxtInput-The name of the text inputs.
Get Item ID using Power Apps gallery Patch
Get Item ID using Power Apps gallery Patch

Next, select the label that is used to retrieve the item’s ID and insert the below expression into the label’s text property.

Text = VarID.ID

Where VarID is the name of the variable and ID is the name of the SharePoint default column name.

Get Item ID using Power Apps gallery Patch function
Get Item ID using Power Apps gallery Patch function

That’s it! Now, save, publish, and play the app. Let’s insert some random data on the respective text inputs.

power apps gallery patch get item ID
power apps gallery patch gets the item ID

When we click the button, we can see that a new item has been added to the Power Apps gallery, and the corresponding ID is displayed on the label.

powerapps patch gallery items and get ID
powerapps patch gallery items and get ID

This is how to get the gallery item’s ID using the patch function within the Power Apps gallery.

Read: Power Apps in SharePoint

Power Apps gallery patch all items

Here, we will see how to update bulk data within a gallery as well as in a data source using a patch. That means when the user clicks on the button, it will update all the items inside the data source or gallery.

Suppose, we have prepared a SharePoint list named ‘Voters List‘ having 3 single lines of text columns such as title, age, address, and a yes/no column named ‘IsEligbleForVoting‘.

powerapps gallery patch all items
powerapps gallery patch all items

We have prepared a gallery using the above SharePoint list below:

powerapps gallery patch for all items
powerapps gallery patch for all items

To update the address and ineligible fields for all, the following steps are:

  • Let’s insert a button control to the app. So that users can update all the fields at a time with a button click.
  • Next, insert a check box control to update the data as ‘Yes/No‘ in both the Power Apps gallery and the SharePoint list.
  • Select the button control and insert the below expression in the OnSelect property.
OnSelect = ForAll('Voters Gallery'.AllItems,Patch('Voters list',{ID:ID,Address:'Address TxtInput'.Text,IsEligibleForVoting:If('IsEligible Chkbox'.Value= true , true , false )}))

Where,

  • Voters Gallery: The name of the gallery
  • Voters list: The name of the SharePoint list
  • ID, Address, IsEligibleForVoting: The columns name of the SharePoint list
  • Address TxtInput: The name of the text input
  • IsEligible Chkbox: The name of the check box control.
Patch all Power Apps gallery items on button click
Patch all Power Apps gallery items on the button click

Now we will save, publish, and play the app in preview mode. Let’s insert an address on the address input and checked the check box control. Then click on the button and we can see the modification is done for all items.

Patch all items Power Apps gallery in SharePoint List
Patch all items Power Apps gallery in SharePoint List

This is how to work with Power Apps gallery patch all items.

Also, check: Power Apps SharePoint Button

Power Apps reset gallery after patch

Here we will see how to reset a gallery once the patch function is done. So that the gallery will be reset once the item is modified or created in the gallery using the patch.

Suppose, we want to modify an existing item in the gallery. Once, it is done, it will reset the gallery.

We’ll implement this using the previous Power Apps gallery, which makes use of SharePoint’s Voters list. We will change the voter name from Alice to Alexa and the address from New York City to Mexico in that gallery, and the gallery will be reset with a button click.

So we will insert the below expression on the button’s OnSelect property.

OnSelect = Patch('Voters list',LookUp('Voters list', ID = 27),{Title:"Alexa",Address:"Mexico"});Reset('Voters Gallery');

Where,

  • Voters list: The name of the SharePoint list
  • ID: To modify the particular item we have used the ID from the SharePoint default column.
  • Voters Gallery: The name of the gallery.
powerapps gallery reset after patch
powerapps gallery reset after patch

It’s done! Save, publish, and play the app for now. We can see when we click on the button, it will modify the specified item as well as reset the gallery like below:

powerapps reset gallery after patch
powerapps reset gallery after patch

This is how to reset a Power Apps gallery after the patch.

Read: Power Apps Navigate Function + 16 Examples

Power Apps gallery reset field after patch

In this section, we will see how to reset the fields after the patch on the Power Apps gallery. That means, we need to reset the input field(s) once after the patch function is done.

Let’s use the above gallery to meet this requirement. In that gallery, we’ve included three text inputs for the voter’s title, age, and address, as well as one checkbox control, to indicate whether the voter is eligible or not. Also, we have added a button control to the app.

power apps gallery reset field after patch
power apps gallery reset field after patch

Now, we’ll add the following expression to the button’s OnSelect property. As a result, with each click, a new item will be added to the gallery. When the item is created, the input fields are immediately reset.

OnSelect = Patch('Voters list',Defaults('Voters list'),{Title:'Title TxtInput'.Text,Age: Value('Age TxtInput'.Text),Address:'Address TxtInput'.Text,IsEligibleForVoting: If('IsEligible Chkbox'.Value = true, true, false)}); Reset('Title TxtInput'); Reset('Age TxtInput');Reset('Address TxtInput'); Reset('IsEligible Chkbox');
Reset field on Power Apps gallery patch
Reset field on Power Apps gallery patch

Save, publish, and play the app in preview mode or press F5. Let’s insert data within the fields to test the app.

Reset inputs on Power Apps gallery patch
Reset inputs on Power Apps gallery patch

Once we click on the button, we can see that a new item has been created in the gallery as well as the fields will reset within the Power Apps. This is how to reset the input field on the Power Apps gallery patch.

Check: Power Apps WeekNum and ISOWeekNum Function with Examples

Power Apps gallery patch selected item

Here, we will see how to patch the selected item within the Power Apps gallery. That means, that when the user selects any item on the gallery, the selected item will be modified.

We’ll use the above gallery, which made use of the SharePoint ‘Voters list.‘ When a user selects an item from the gallery, the ‘IsEligible‘ column value changes to False.

To accomplish this, we have included a Right icon within the gallery, which will be visible in each row of the gallery.

powerapps gallery patch selected item
powerapps gallery patch selected item

Select the icon and insert the below expression inside the icon’s OnSelect property.

OnSelect = Patch('Voters list', 'Voters Gallery'.Selected,{IsEligibleForVoting:false})
Selected Gallery Item Changes on Patch Function
Selected Gallery Item Changes on Patch Function

Save, publish, and run the app now. As we can see, clicking on any item’s icon causes the item’s value to change. If we select the second item’s icon (i.e., Johnson), the IsEligible value will be set to False like below:

Update selected item from Powerapps gallery using Patch
Update selected item from Powerapps gallery using Patch

This is how to update a selected item from the PowerApps gallery using Patch.

Power Apps patch gallery dropdown

In this section, we will see how to patch a Power Apps gallery using a dropdown value. We have prepared a Power Apps gallery using a SharePoint list named ‘Orders list‘ that contains 3 columns such as Title (Default), OrderDate (Date and Time), and Department(Choices).

On that app, we have inserted a text Input to insert the product name, a dropdown control to select the department, and a button to update the gallery.

On the dropdown, we have inserted the below expression to retrieve the choices from the SharePoint choice column. Select the dropdown and insert the below expression on the ‘Items‘ property.

Items = Choices('Orders List'.Department)
powerapps patch gallery dropdown
powerapps patch gallery dropdown

Select the button and insert the below patch expression in the OnSelect property to save the data on the gallery.

OnSelect = Patch('Orders List', Defaults('Orders List'),{Title:ProductTextInput.Text, Department:Department_Dropdown.Selected, OrderDate:Date(2022,8,25)})

Where,

  • Orders List: The name of the SharePoint data source
  • Title, Department, OrderDate: The name of the SharePoint column
  • Department_Dropdown: The name of the dropdown control
powerapps patch gallery select dropdown
powerapps patch gallery select dropdown

Now, save and publish the app. Play it on preview mode. Let’s insert a product name within the text input and select an option from the dropdown. We can see, that when we click on the button, the item will be saved immediately on the gallery like below:

Patch a Gallery and DropDown Values
Patch a Gallery and DropDown Values

This is how to patch a gallery and dropdown Values on Power Apps.

Also check: PowerApps form benefits for SharePoint

Power Apps gallery patch date

InIn this section, we’ll look at how to add a date column to the Power Apps gallery. On the above gallery, we used a date column called “OrderDate,” and we manually patched the date field. However, if the user selects a date from the date picker, it will patch the selected date to the Power Apps gallery.

For this, we will insert a date picker into the app, so that users can select any date as per their choice. Click on the Insert > Inputs > Date Picker.

powerapps patch gallery date
powerapps patch gallery date

Similarly, select the button control and insert the below expression on the OnSelect property.

OnSelect = Patch('Orders List', Defaults('Orders List'),{Title:ProductTextInput.Text, Department:Department_Dropdown.Selected, OrderDate:OrderDatePicker.SelectedDate})

Where OrderDate is the name of the SharePoint date column, and OrderDatePicker is the name of the date picker.

How to patch Date in a SharePoint list to Power Apps gallery
How to patch Date in a SharePoint list to Power Apps gallery

Save, publish, and run the app. Insert the appropriate data into the input fields and choose a date from the date picker. Once the button is clicked, the data in the date field will be saved in the gallery.

PATCH A SharePoint Date Column In Power Apps
Patch A SharePoint Date Column In Power Apps gallery

This is how to patch a SharePoint date column in the Power Apps gallery.

Read: PowerApps tips and tricks

Power Apps patch collection to the gallery

Here, in this section, we’ll look at how to use a patch collection with the Power Apps gallery. That means we can add multiple items to the SharePoint list via patch collection and retrieve them to a Power Apps gallery.

First, we will create a collection on the Power Apps screen, and then patch that collection to the SharePoint list. To do this, the following steps are:

  • First, we will prepare a SharePoint list so that the multiple data will store there from the collection. We have prepared a SharePoint list named ‘AcademicResults‘ having columns such as Title, LastName, Score, and Contact.
powerapps add gallery to collection
powerapps add collection to the gallery
  • On the Power Apps, we will use a collect function within an expression to create a collection that holds multiple records. On the Power Apps screen, insert the following expression on the OnVisible property.
OnVisible = ClearCollect(ColResults,{Title:"John",LastName:"Willium",Score:85,Contact:1234567890},{Title:"Ronnie",LastName:"Green",Score:76,Contact:0123456789},{Title:"Albert",LastName:"Johnson",Score:96,Contact:332127890})

Where,

  • ColResults – The name of the collection
  • Title, LastName, Score, Contact – The name of the collection columns. Here, we have created the collection’s column as similar to
powerapps add gallery patch to collection
powerapps add gallery patch to collection
  • We can find the collection under the View on the Power Apps. Go to View > Collections.
view collections on the Power Apps
view collections on the Power Apps

Note- If you cannot find the collection, once it has been created, save and publish the app, then close and reopen it. You can get the collection this time.

  • Next, move to the Power Apps screen. On that screen, add a button and insert the below patch function on the button’s OnSelect property. When the user clicks on the button, it will patch all of the collected data to the SharePoint list.
OnSelect = ForAll(ColResults,Patch(AcademicResults,Defaults(AcademicResults),{Title:Title, LastName: LastName, Score:Score,Contact:Contact}))

Here,

  • ColResults – The name of the Collection
  • AcademicResults – The name of the SharePoint list
  • Title: Title – The first Title is the name of a SharePoint column, and the second is the name of a collection column. We did the same thing with the other columns.
powerapps add gallery to patch collection
powerapps add a gallery to patch collection
  • Let’s add a gallery to the screen, and set the SharePoint list i.e. AcademicResults on the items property of the gallery. So that when the user clicks on the button, the items will be created in the SharePoint list and it will display in the gallery.
  • Now, save, publish, and play the app. Then Click on the button, and we can see all the items that have been created in the SharePoint list.
patch Multiple Records In Power Apps gallery collection
patch Multiple Records In Power Apps gallery collection

We can also see that the gallery now contains all of this information.

How PowerApps Patch Collection in gallery
How PowerApps Patch Collection in gallery

This is how to do patch collection in the Power Apps gallery.

Read Power Apps combo box filter

Power Apps gallery patch Number

Here, we will see how to patch a number to a Power Apps gallery. We are going to use the previous SharePoint list ‘AcademicResults.’ On that list, we want to update Ronnie Green’s score from 76 to 86. Here the score is a number type column.

Power Apps gallery patch Number
Power Apps gallery patch Number

Let’s create a gallery using the above list. To do this, we need to insert a button on the screen and insert the below expression on the ‘OnSelect’ property.

OnSelect = Patch(AcademicResults, LookUp(AcademicResults, ID = 18),{Score:86})

Where,

  • AcademicResults: The name of the data source.
  • ID =18: The ID of the specified Item.
  • Score: The column that has to be changed.
powerapps patch gallery Number
powerapps patch gallery Number

Now save, publish, and play the app in preview mode. We can see it will update the score of the specified person.

powerapps patch gallery Number to sharepoint
powerapps patch gallery Number to SharePoint

Also, we can see this update on the SharePoint list. This is how to patch a number via the Power Apps gallery.

Check: PowerApps nested gallery control example

Power Apps gallery patch Person Field

In this section, we will see how to patch a person field on the Power Apps gallery. Suppose, we have a SharePoint task list including a person field named ‘Assigned to.

powerapps patch gallery person Field
powerapps patch gallery person Field

Now we’d like to change the Assigned To on the second item from Roselin to Sonam. To do this, teh following steps are:

  • Build a Power Apps gallery using the above SharePoint list.
  • Add a button control to the app. So that when the user clicks on the button, it will update the person’s field value. Select the button control and insert the following expression within the button’s OnSelect property.
OnSelect = Patch(
    'Task list',
    LookUp(
        'Task list',
        ID = 41
    ),
    {
        'Assigned To': {
            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
            Claims: "i:0#.f|membership|[email protected]",
            Department: "",
            DisplayName: "Sonam subhadarsini",
            Email: "[email protected]",
            JobTitle: "",
            Picture: ""
        }
    }
)

Where,

  • Task list: The name of the SharePoint list.
  • ID: The default column of the SharePoint list to identify the specified item.
  • Assigned To: The name of SharePoint’s person field.
patch person field Person Column In Power Apps gallery
patch person field Person Column In Power Apps gallery

Now, save, publish, and play the app. We can see the person field’s value will be changed once the button is clicked like below:

Power Apps gallery patch person field
Power Apps gallery patch person field

This is how to patch a SharePoint person field from the Power Apps gallery.

Read: SharePoint PowerApps Example – Get bank branch details based on State

Power Apps patch gallery check box or powerapps patch gallery thisitem

This section will demonstrate how to patch a check box or use this item to patch a gallery in Power Apps. Instead of creating a new item, when the user checks the checkbox, it is updated in the SharePoint list.

Suppose we have a SharePoint list named “Employees” that has a Yes/No column, i.e., Active.

powerapps patch gallery check box
powerapps patch gallery check box

We have created a Power Apps gallery, using the above SharePoint list where we have added a check box control to update the Active field in the list from the Power Apps gallery.

powerapps gallery patch check box
powerapps gallery patch check box

Insert the following expression into the OnCheck property to update the data source when the user checks the checkbox.

OnCheck = Patch( Employees, ThisItem, {Active:true})
power apps gallery patch thisitem
power apps gallery patch thisitem

Let’s save, publish, and play the app. Suppose, we have checked 2 items on the gallery’s checkbox.

power apps patch gallery thisitem
power apps patch gallery thisitem

We can see, it will update in the SharePoint list as well.

powerapps patch gallery with check box
Powerapps patch gallery with the check box

This is how to patch the Power Apps gallery with a selected check box.

Also, you may like some more Power Apps tutorials:

Conclusion

This Power Apps Tutorial covered the use of the patch function within the Power Apps gallery. In addition, we have covered the following topics:

  • What is the patch function in Power Apps?
  • Discuss the different types of patch function syntax in Power Apps.
  • How to work with SharePoint list using Power Apps gallery patch?
  • How to update an existing item using the patch function within the Power Apps gallery?
  • How to get the item’s ID using the patch function in the Power Apps gallery?
  • How to patch all items in the Power Apps gallery?
  • How to reset the Power Apps gallery after patching?
  • How to reset the input field in the Power Apps gallery?
  • How to patch the selected item in the powerapps gallery?
  • How to patch a powerapps gallery with dropdown selections?
  • How to patch a powerapps gallery with date inputs?
  • How to patch collections to a powerapps gallery?
  • How to patch the Number in a powerapps gallery?
  • How to patch PowerApps Gallery with a person field?
  • How to patch the powerapps gallery check box?
  • >