Fastest Way To Patch All Gallery Items In Power Apps (2024)

It is useful to know how to patch all items in a gallery when you want to update several items in a SharePoint list at once. To perform batch updates you can use a little-known variation of the patch function. This offers faster performance than the traditional ForAll + Patch Function approach which performs the patches one-by-one.

Table of Contents• Introduction: The Equipment Serial Numbers AppSetup The SharePoint ListInsert A Gallery Into The Canvas AppAdd A Text Input Field To The GalleryPatch Gallery Updates To SharePoint ListHandle Errors When Patching Gallery UpdatesCancel Updates Made To The Gallery

Introduction: The Equipment Serial Numbers App

Employees at a farm equipment repair company track their customer’s equipment inside of an app. The repair company records the serial number of each part inside the equipment for warranty purposes.

Fastest Way To Patch All Gallery Items In Power Apps (1)

Create a new SharePoint list named Equipment Serial Numbers with the following columns:

  • ID
  • EquipmentName (single-line text)
  • Title (single-line text)
  • SerialNumber (single-line text)

Populate the SharePoint list with the following values:

IDEquipmentNameTitleSerialNumber
1Tractor 1Engine12345
2Tractor 1Front Axle56789
3Tractor 1Brakes56789
4Tractor 1Gear Box45678
5Tractor 1Differential23456
6Tractor 1PTO45678
7Tractor 1Steering System98765
8Tractor 1Rear Linkages12345

After the values are input into the Equipment Serial Numbers SharePoint list it will look like this.

Fastest Way To Patch All Gallery Items In Power Apps (2)

Insert A Gallery Into The Canvas App

Open Power Apps Studio and start a new canvas app from a blank screen. Add a label with the words Equipment Serials to act as the titlebar. Then create two more labels with the words Title and Serial Number to serve as headings for the gallery.

Fastest Way To Patch All Gallery Items In Power Apps (3)
Fastest Way To Patch All Gallery Items In Power Apps (4)

Use this code in the Items property of the gallery.

'Equipment Serial Numbers'

Add A Text Input Field To The Gallery

We want to display all rows from Equipment Serial Numbers in the gallery and give the user a way to edit the serial numbers. Insert a label into the gallery to display the Title.

Fastest Way To Patch All Gallery Items In Power Apps (5)

Use this code in the Text property of the label.

ThisItem.Title

Then add a text input control to the gallery for the user to write-in a serial number.

Fastest Way To Patch All Gallery Items In Power Apps (6)

Use this code in the Default property of the text input. When the SharePoint list item has a serial number it will be display as the text input’s initial value.

ThisItem.SerialNumber

When the user presses the Save button we want to write all of the text input fields whose values changed to SharePoint. We will exclude any unchanged text inputs from the set of updates.

Fastest Way To Patch All Gallery Items In Power Apps (7)

Write this code in the OnSelect property of the Save button. First, we create a collection named colGalleryUpdates to capture any rows in the gallery that changed. We do this by filtering the gallery to only show rows where the SerialNumber in SharePoint does not match the Serial Number from the text input. Notice that the SharePoint column name is inside of a Text function. This is necessary to prevent to change any null values in SharePoint to a blank text string for comparison.

Then we use the Patch function to write the updated values in colGalleryUpdates to SharePoint. When the changes are completed we show a success notification at the top of the screen.

// create a collection of SharePoint list items to be updatesClearCollect( colGalleryUpdates, ForAll( Filter( gal_EquipSerials_List.AllItems, Text(SerialNumber) <> txt_EquipSerials_SerialNo.Text ), { ID: ThisRecord.ID, SerialNumber: ThisRecord.txt_EquipSerials_SerialNo.Text } ));// update SharePoint list with gallery valuesPatch( 'Equipment Serial Numbers', colGalleryUpdates.ID, colGalleryUpdates);// show a success notificationNotify( $"{CountRows(colGalleryUpdates)} serial number(s) updated successfully", NotificationType.Success);// reset the galleryReset(gal_EquipSerials_List)

Preview the app and write some values serial number into the serial numbers fields. When we press the Save button the values are updates in SharePoint.

Fastest Way To Patch All Gallery Items In Power Apps (8)

Handle Errors When Patching Gallery Updates

We cannot safely assume that patching the gallery updates to SharePoint will happen without any errors. A dropped network connection could interrupt the update. Or maybe the user did not make any changes before pressing Save and there is nothing to updates. For these reasons and more we must build error-handling into our code.

Fastest Way To Patch All Gallery Items In Power Apps (9)

Update the gallery Items code with these changes. The IsError function is used to check whether the Patch function executed successfully. Then an error message is displayed in the event of a failure. The code also includes a condition to check for no changes to the gallery.

// create a collection of SharePoint list items to be updatesClearCollect( colGalleryUpdates, ForAll( Filter( gal_EquipSerials_List.AllItems, Text(SerialNumber) <> txt_EquipSerials_SerialNo.Text ), { ID: ThisRecord.ID, SerialNumber: ThisRecord.txt_EquipSerials_SerialNo.Text } ));If( // check whether any updates were made to the gallery !IsEmpty(colGalleryUpdates), If( IsError( // update SharePoint list with gallery values Patch( 'Equipment Serial Numbers', colGalleryUpdates.ID, colGalleryUpdates ) ), // show an error notification Notify( "Serial numbers update failed", NotificationType.Error ), // show a success notification Notify( $"{CountRows(colGalleryUpdates)} serial number(s) updated successfully", NotificationType.Success ) ), // show error notification for no changes Notify( "No serial numbers were changed before save", NotificationType.Error ));// reset the galleryReset(gal_EquipSerials_List)

Cancel Updates Made To The Gallery

A user may decide they do not want to keep the changes they have made to the gallery. We will provide them with a cancel button to revert the gallery back to the current values in SharePoint. Create a new button with the text Cancel and place it beside the save button.

Fastest Way To Patch All Gallery Items In Power Apps (10)

Write this code in the OnSelect property of the Cancel button. The variable gblResetGallery is toggled on and off to trigger a reset of the text inputs while the Reset Function moves the gallery back to the top position if it has been scrolled down.

Set(gblResetGallery, true);Set(gblResetGallery, false);Reset(gal_EquipSerials_List)

Then go to the text input and update the Reset property.

Fastest Way To Patch All Gallery Items In Power Apps (11)

Use this value in the Reset property of the gallery.

gblResetGallery

Run the app in preview mode. Enter a few values into the text inputs then press Cancel. The text fields will revert to their original values.

Fastest Way To Patch All Gallery Items In Power Apps (12)

Did You Enjoy This Article? 😺

Subscribe to get new Power Apps & Power Automate articles sent to your inbox each week for FREE

Questions?

If you have any questions or feedback about Fastest Way To Patch All Gallery Items In Power Apps please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.

Fastest Way To Patch All Gallery Items In Power Apps (2024)
Top Articles
Temecula, CA New Construction Homes for Sale | realtor.com®
Bibliographies: 'Women's health and well-being, Taiwan' – Grafiati
Stockmans Meat Company
Craigslist Kentucky Cars And Trucks - By Owner
Dover Nh Power Outage
Feet.girl01
Best Places To Get Free Furniture Near Me | Low Income Families
Steve Wallis Wife Age
Nosetf
Tampa Lkq Price List
Pepsi Collaboration
Cvs Tb Testing Cost
Ta Travel Center Las Cruces Photos
5 Best Vanilla Vodka co*cktails
Magic Seaweed Pleasure Point
Meet Scores Online 2022
Cosmoprof Jobs
Caribbean Mix Lake Ozark
Itawamba Ixl
Hotleak.vip
Ice Crates Terraria
Dmv Rocklin Wait Times
Weird Al.setlist
Scenes from Paradise: Where to Visit Filming Locations Around the World - Paradise
Numerous people shot in Kentucky near Interstate 75, officials say | CNN
Blackwolf Run Pro Shop
Atlanticbb Message Center
Best Birthday Dinner Los Angeles
Kraken Strategy Osrs
Kristen Stewart and Dylan Meyer's Relationship Timeline
Rugrats in Paris: The Movie | Rotten Tomatoes
Craigslist Cars Los Angeles
Locals Canna House Deals
Free Stuff Craigslist Roanoke Va
Comcast Xfinity Outage in Kipton, Ohio
Help with Finding Parts for Your Vehicle
Sky Nails Albany Oregon
Barney Min Wiki
Tények este teljes adás, 2024. április 26., péntek
Let's Take a Look Inside the 2024 Hyundai Elantra - Kelley Blue Book
Www.craiglist.com San Antonio
Ny Lottery Second Chance App
Bob Wright Yukon Accident
Kona Airport Webcam
North Haven Power School
Webworx Call Management
Cetaphil Samples For Providers
Cheap Cars for Sale in Colorado Springs, CO
Is Gary Hamrick Calvinist
Dtm Urban Dictionary
Gunsmoke Noonday Devil Cast
Horoskopi Koha
Latest Posts
Article information

Author: Fr. Dewey Fisher

Last Updated:

Views: 6203

Rating: 4.1 / 5 (42 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Fr. Dewey Fisher

Birthday: 1993-03-26

Address: 917 Hyun Views, Rogahnmouth, KY 91013-8827

Phone: +5938540192553

Job: Administration Developer

Hobby: Embroidery, Horseback riding, Juggling, Urban exploration, Skiing, Cycling, Handball

Introduction: My name is Fr. Dewey Fisher, I am a powerful, open, faithful, combative, spotless, faithful, fair person who loves writing and wants to share my knowledge and understanding with you.