cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Microsoft
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
Highlighted
Community Champion
Community Champion

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
Highlighted
Power Participant
Power Participant

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/

Highlighted
Advocate IV
Advocate IV

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?

Highlighted
Power Participant
Power Participant

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.

Highlighted
Power Participant
Power Participant

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

Highlighted
Advocate IV
Advocate IV

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.

Highlighted
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

Highlighted
Community Champion
Community Champion

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
Highlighted
Anonymous
Not applicable

Re: Editing multiple records in Gallery control

Thank you @hpkeong 🙂

 

Highlighted
Community Champion
Community Champion

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
Ignite

Microsoft Ignite

This will be a conference that you do not want to miss!

secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (5,002)