cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Microsoft MAV_CB
Microsoft

Editing multiple records in Gallery control

Anyone have any tips and tricks for doing a multiple record update? I have a Gallery loading SharePoint list items and I want to be able to update multiple records at once (such as deleting records that have a checkbox in their gallery record ticked). Another scenario is where each record has a Yes/No column where I am using a Checkbox as the control, and want users to tick/untick boxes record by record and "Save" those changes.

1 ACCEPTED SOLUTION

Accepted Solutions
hpkeong
Level 10

Re: Editing multiple records in Gallery control

Hi @MAV_CB

 

I have posted one of Useful Features of PowerApps (15): Multiple / Batch Records Editing.

 

https://powerusers.microsoft.com/t5/PowerApps-Forum/Useful-features-of-powerapps-15-Multiple-Batch-R...

 

Hope this helps

hpkeong

View solution in original post

16 REPLIES 16
Steelman70
Level 10

Re: Editing multiple records in Gallery control

Here is an idea, please let me know if anything is unclear, need more details, or you get stuck.

 

1) Use the Collect function to create a collection (MyCollection) of the item IDs that you need to delete/update, for example by adding/removing the item to/from the MyCollection when the box is ticked/unticked in the gallery

2) For the delete button (outside the gallery) set the OnSelect to use the RemoveIf, where the condition is that the records are in MyCollection or alternatively use the Remove( DataSource, MyCollection [, All ] ) type of syntax

3) For the save all changes button (outside the gallery) set the OnSelect to UpdateIf, where the condition is that the records are in MyCollection

 

Find out more about these functions here:

https://powerapps.microsoft.com/en-us/tutorials/working-with-variables/#create-a-collection

https://powerapps.microsoft.com/en-us/tutorials/function-remove-removeif/

https://powerapps.microsoft.com/en-us/tutorials/function-update-updateif/

opax
Level: Powered On

Re: Editing multiple records in Gallery control

Hi,

 

I can make the 2) removing multiple items at once work, but could not solve how to update multiple records.

 

This is how I did the number 2:

- On each item there is a thrashbin icon:

OnSelect = If(CountRows(Filter(ItemToRemove, Id = ThisItem.Id)) = 0, Collect(ItemToRemove, ThisItem), RemoveIf(ItemToRemove, Id=ThisItem.Id))

- To highlight the selected, I did this:

Fill = If(CountRows(Filter(ItemToRemove, Id = ThisItem.Id)) = 0, White, DarkRed)

And the formula for the remove button:

RemoveIf('[dbo].[Table1]',Id in ItemToRemove);Clear(ItemToRemove)

 

This is how I tried to do the number 3 (updating multiple items):

- On each control in a row I added:

OnChange = If(CountRows(Filter(ItemToUpdate, Id = ThisItem.Id)) = 0, Collect(ItemToUpdate, {Id: ThisItem.Id}))

- To save I tried this (doesn't highlight an error - but doesn't work):

OnSelected = UpdateIf('[dbo].[Table1]',Id in ItemToUpdate, Gallery1.Updates);Clear(ItemToUpdate);Refresh('[dbo].[Table1]')

 

The problem is that syntax of UpdateIf requires that you should be able to create pairs of conditions and records:

UpdateIf( DataSource, Condition1, ChangeRecord1 [, Condition2, ChangeRecord2, ... ] )

 

It would work if I could do foreach loop or something.

 

Any ideas?

Steelman70
Level 10

Re: Editing multiple records in Gallery control

Hi, this is getting interesting, hopefully I can get some kudos for this!  Let me take your two points in two different posts.

 

Number 2:

Your approach is good and works, well done.  However, I have since discovered a simpler approach which avoids the use of a collection and uses a checkbox control in the gallery.  The key is that you can refer to the value of a control in a gallery directly!  You use the disambiguation operator @ to match the ID in the gallery to the ID in your source!

Hopefully this will be clear from the following screenshot, but please let me know if it is not.

 

CaptureRemoveIf.JPG

 

There may be even better approaches by filtering the source by the checkbox before removing all items, but I haven't tried this yet.

Steelman70
Level 10

Re: Editing multiple records in Gallery control

Number 3:

 

Hopefully you will be really impressed by this one, the approach is the same as for 2.  I use your approach for the collection.

I have not used the Updates property of Gallery1 because frankly I only first noticed it in your post.  Let me see if that can yield an even better result.  In any case again please let me know if anything is not clear.  By the way, if you have more than one field to update, you use the inline syntax 

 

CaptureSaveAll.JPG

opax
Level: Powered On

Re: Editing multiple records in Gallery control

Thanks!

 

I confirm that with the instructions I could make both cases work. 🙂

 

Multiple updates saved with one click is one of the key use cases on the PoC I'm working on. It is so important from the usability perspective.

Anonymous
Not applicable

Re: Editing multiple records in Gallery control

Hi @opax,

 

I try to work on same senario. it's works when database is collectipn. But my database is Common Data Model and function is: 

 

UpdateIf('ListA',ogr_no<>"", {durum:LookUp(BrowseGallery1.AllItems, ogr_no='ListeA'[@ogr_no]).checkbox1.Value})

 

Do you have any idea?

 

Thanks & Regards

hpkeong
Level 10

Re: Editing multiple records in Gallery control

Hi @Anonymous

 

I have posted one of Useful Features of PowerApps (15): Multiple / Batch Records Editing.

 

https://powerusers.microsoft.com/t5/PowerApps-Forum/Useful-features-of-powerapps-15-Multiple-Batch-Records-Adding/m-p/9883#M4370

 

Hope this helps.

hpkeong
Anonymous
Not applicable

Re: Editing multiple records in Gallery control

Thank you @hpkeong 🙂

 

hpkeong
Level 10

Re: Editing multiple records in Gallery control

Hi @opax

 

I have posted one of Useful Features of PowerApps (15): Multiple / Batch Records Editing.

 

https://powerusers.microsoft.com/t5/PowerApps-Forum/Useful-features-of-powerapps-15-Multiple-Batch-R...

 

Hope this helps

hpkeong

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (3,658)