How to Patch Gallery Items in Power Apps? (Single & Bulk) - SharePoint & Microsoft Power Platform Tutorials - SPGuides (2024)

A few days ago, I developed a leave management application for Power Apps. In it, employee leave requests undergo two-level approvals, so I created a dashboard for approvers to approve or reject single and multiple requests at a time with the help of the Power Apps Patch function.

In this article, I will explain how to patch a single gallery item in Power Apps and show various examples of how to patch all gallery items in Power Apps.

Table of Contents

Power Apps Patch Gallery Selected Item [Single Item Only]

In my leave management application, the employee leave requests undergo two levels of approval. So, I displayed all employee leave requests in the Power Apps gallery control in the dashboard.

When approver 1 selects a pending leave request, he can provide comments and approve or reject it by clicking on the buttons. If he approves, the status will be updated as Approver 2 Pending; if he rejects it, it will be updated as Approver 1 Rejected.

When approver 2 approves the leave request, the status value is updated asApprover 2 Approved. If he rejects it, it will be updated as Approver2 Rejected. Approver2 can also provide comments that will be saved to the SharePoint list. The example below displays the same thing.

How to Patch Gallery Items in Power Apps? (Single & Bulk) - SharePoint & Microsoft Power Platform Tutorials - SPGuides (1)

Here is the SharePoint list that contains employee leave requests.

How to Patch Gallery Items in Power Apps? (Single & Bulk) - SharePoint & Microsoft Power Platform Tutorials - SPGuides (2)
Column NameData Type
Leave TitleSingle line of text
Employee NamePerson
Leave TypeChoice(Sick ,Maternity, Annual, Compassionate)
Start DateDate & Time
End DateDate & Time
DepartmentChoice(IT,Sales,Marketing,HR)
Leave DaysNumber
Approver CommentsMultiline text
Manager NameSingle line of text
StatusChoice(Approver1 Pending,Approver1 Approved,Approver1 Rejected,Approver2 Pending,Approver2 Approved,Approver3 Rejected)

1. In Power Apps, add a gallery control and provide the SharePoint list name below in its Items property.

'Employee Leave Requests'
How to Patch Gallery Items in Power Apps? (Single & Bulk) - SharePoint & Microsoft Power Platform Tutorials - SPGuides (3)

2.In the gallery, to differentiate the status value of each leave request, add the below code in the Fill property of the status text label. Also, if you’re unaware of getting status value in the gallery, add the below code in its Text property.

Text = ThisItem.Status.Value
Fill = If( ThisItem.Status.Value = "Approver1 Pending", RGBA(174, 208, 221, 1), ThisItem.Status.Value = "Approver1 Rejected", RGBA(233, 79, 76, 0.83), ThisItem.Status.Value = "Approver2 Pending", RGBA(109, 49, 162, 0.68), ThisItem.Status.Value = "Approver2 Approved", RGBA(72, 163, 62, 0.9), ThisItem.Status.Value = "Approver2 Rejected", RGBA(233, 79, 76, 0.83))

Based on status values, the proved color will be applied to the status text label in the gallery.

How to Patch Gallery Items in Power Apps? (Single & Bulk) - SharePoint & Microsoft Power Platform Tutorials - SPGuides (4)

3. Add a Power Apps form control and provide the codes for its properties given below.

DataSource ='Employee Leave Requests'Item = Gal_EmpLeaveRequest.Selected

To display the gallery-selected item in the form control, we need to pass the above code in the item property of the form control.

  • Gal_EmpLeaveRequest = Gallery name.
  • ‘Employee Leave Requests’ = SharePoint list name.

Note:Except for the approver comments data card, all remaining Display Modes of the data cards are as View.

How to Patch Gallery Items in Power Apps? (Single & Bulk) - SharePoint & Microsoft Power Platform Tutorials - SPGuides (5)

4. Add two button controls for approve and reject. Then, add the codes below to its OnSelect property.

Approve button’s OnSelect property:

If( Gal_EmpLeaveRequest.Selected.Status.Value = "Approver1 Pending", Patch( 'Employee Leave Requests', Gal_EmpLeaveRequest.Selected, { Status: {Value: "Approver2 Pending"}, 'Approver Comments': DataCardValue18.Text } ), Gal_EmpLeaveRequest.Selected.Status.Value = "Approver2 Pending", Patch( 'Employee Leave Requests', Gal_EmpLeaveRequest.Selected, { Status: {Value: "Approver2 Approved"}, 'Approver Comments': DataCardValue18.Text } ))

Here,

  • Gal_EmpLeaveRequest = Gallery name.
  • ‘Employee Leave Requests’ = SharePoint list name.
  • DataCardValue18 = Approver comments data card value name in the form control.
  • If the status value is “Approver1 Pending,” it will update as “Approver2 Pending.” Also, comments will updated.
  • If the status value is “Approver2 Pending,” it will update as “Approver2 Approved”, comments are also updated.
How to Patch Gallery Items in Power Apps? (Single & Bulk) - SharePoint & Microsoft Power Platform Tutorials - SPGuides (6)

Reject button’s OnSelect property:

If( Gal_EmpLeaveRequest.Selected.Status.Value = "Approver1 Pending", Patch( 'Employee Leave Requests', Gal_EmpLeaveRequest.Selected, { Status: {Value: "Approver1 Rejected"}, 'Approver Comments': DataCardValue18.Text } ), Gal_EmpLeaveRequest.Selected.Status.Value = "Approver2 Pending", Patch( 'Employee Leave Requests', Gal_EmpLeaveRequest.Selected, { Status: {Value: "Approver2 Rejected"}, 'Approver Comments': DataCardValue18.Text } ))

This code will update the status value like in the below conditions:

  • If the status value is “Approver1 Pending, ” it will update as “Approver1 Rejected.” Also, the comments will be updated.
  • If the status value is “Approver2 Pending,” it will update to “Approver2 Rejected.” Comments will also be updated.
How to Patch Gallery Items in Power Apps? (Single & Bulk) - SharePoint & Microsoft Power Platform Tutorials - SPGuides (7)

Save the changes and preview the application. When you click the approve or reject buttons, the status values in the Power Apps gallery are updated based on the conditions I explained in the introduction.

This way, we can patch the selected item in the Power Apps gallery. Let’s see how to patch multiple items in Power Apps gallery control.

Patch All Gallery Items in Power Apps

With the above example, we’ll also try how to patch multiple Power Apps gallery items. In the example below, you can see that when I click on the Select all check box, the items in the gallery are selected, and when I click on the Approve button based on the status value, it is updated. This is also true for the reject button.

How to Patch Gallery Items in Power Apps? (Single & Bulk) - SharePoint & Microsoft Power Platform Tutorials - SPGuides (8)

Follow the steps below to achieve this!

1. Add a checkbox control to the Power Apps gallery control. Then, provide the formulas below for the provided properties. Remove the text property value.

OnCheck =Collect(colItems,ThisItem)OnUnCheck = RemoveIf(colItems,ID=ThisItem.ID)

Here, we’re creating a Power Apps collection named colItems to store gallery-selected items. The Removeif function removes the unchecked item in the gallery.

How to Patch Gallery Items in Power Apps? (Single & Bulk) - SharePoint & Microsoft Power Platform Tutorials - SPGuides (9)

2. Add another Power Apps check box control and provide the formulas below for the provided properties.

OnCheck = Collect(colItems,'Employee Leave Requests')OnUnCheck = Clear(colItems);Text = "Select All"

To get the details directly from the SharePoint list, we’re creating a collection again in the OnCheck property of the select all check box.

When we uncheck the select all check box, the data present in the collection is cleared.

How to Patch Gallery Items in Power Apps? (Single & Bulk) - SharePoint & Microsoft Power Platform Tutorials - SPGuides (10)

3. Now provide the below formulas for approve and reject buttons in its OnSelect property.

ForAll(colItems,Switch( true, ThisRecord.Status.Value = "Approver1 Pending", Patch( 'Employee Leave Requests', ThisRecord, { Status: {Value: "Approver2 Pending"}, 'Approver Comments': DCV_ApproverComments.Text } ), ThisRecord.Status.Value = "Approver2 Pending", Patch( 'Employee Leave Requests', ThisRecord, { Status: {Value: "Approver2 Approved"}, 'Approver Comments': DCV_ApproverComments.Text } ) ))

Here, the ForAll function took each record in the collection based on its status value and updated the next status.

How to Patch Gallery Items in Power Apps? (Single & Bulk) - SharePoint & Microsoft Power Platform Tutorials - SPGuides (11)

Reject buttons OnSelect property:

ForAll(colItems,Switch( true, ThisRecord.Status.Value = "Approver1 Pending", Patch( 'Employee Leave Requests', ThisRecord, { Status: {Value: "Approver1 Rejected"}, 'Approver Comments': DCV_ApproverComments.Text } ), ThisRecord.Status.Value = "Approver2 Pending", Patch( 'Employee Leave Requests', ThisRecord, { Status: {Value: "Approver2 Rejected"}, 'Approver Comments': DCV_ApproverComments.Text } ) ))

Based on the status value, it will update each record in the Power Apps collection, and the status will be updated.

How to Patch Gallery Items in Power Apps? (Single & Bulk) - SharePoint & Microsoft Power Platform Tutorials - SPGuides (12)

Save the changes and preview the app once. Click on the select all check box, which will select all items in the gallery. Then click the approve or reject buttons, which will update the status, as seen in the gallery itself.

I hope you understand the patch Power Apps gallery selected single and multiple items. In this article, I explained the Power Apps patch function and how to simultaneously patch gallery-selected items and bulk items.

Also, you may like:

  • Power Apps sort gallery by person column
  • Power Apps sort gallery by ID
  • Add a new row in Power Apps gallery control
  • Count rows in Power Apps gallery control
  • Download a File from Power Apps

How to Patch Gallery Items in Power Apps? (Single & Bulk) - SharePoint & Microsoft Power Platform Tutorials - SPGuides (13)

Bijay Kumar

I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com

How to Patch Gallery Items in Power Apps? (Single & Bulk) - SharePoint & Microsoft Power Platform Tutorials - SPGuides (2024)
Top Articles
Latest Posts
Recommended Articles
Article information

Author: Corie Satterfield

Last Updated:

Views: 5683

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Corie Satterfield

Birthday: 1992-08-19

Address: 850 Benjamin Bridge, Dickinsonchester, CO 68572-0542

Phone: +26813599986666

Job: Sales Manager

Hobby: Table tennis, Soapmaking, Flower arranging, amateur radio, Rock climbing, scrapbook, Horseback riding

Introduction: My name is Corie Satterfield, I am a fancy, perfect, spotless, quaint, fantastic, funny, lucky person who loves writing and wants to share my knowledge and understanding with you.