cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Lexicron
Resolver II
Resolver II

How to collect all visible items in a filtered Gallery into an existing collection? ClearCollect(Collection, Gallery.AllItems) results in conflict in other areas dealing with the same Collection.

I have a Gallery with items from a CDS entity. It is filtered so it never shows all records. I have a Collection meant for those items.

 

Each template in the Gallery has a Checkbox with the following formulas:

 

OnCheck: Collect(Collection, ThisItem)
OnUnCheck: Remove(Collection, ThisItem)
Default: ThisItem in Collection

 

 

Outside of my Gallery I have a Deselect button with the following formula:

 

OnSelect: Clear(Collection)

 

 

Clicking it will also clear any checkboxes due to their default value.

 

Everything above works perfectly. Below is where it fails.

 

Also outside of my Gallery, I want a SelectAll button to collect all visible items in my Gallery into the same Collection. Once it has done that, all my checkboxes will show up checked appropriately due to their Default value being tied to their participation in the Collection.

 

I have read many other posts here. I cannot achieve this by:

  • setting SelectAll.OnSelect = Set(varAllSelected, true)
  • setting Checkbox.Default = If(ThisItem In Collection, true, varAllSelected)

because it is not enough to have the ✓ show up, it is not the value of the checkbox that puts the item in the collection but the action of checking it. So doing this doesn't add it to Collection.

 

I tried the following formula:

 

OnSelect: ClearCollect(Collection, Gallery.AllItems)

 

 

But I get an error on my Checkbox.OnCheck and Checkbox.OnUnCheck formulas, saying the item I'm trying to add to a collection is not of a compatible type. 

 

Why is AllItems not the same type as ThisItem?

 

I've also tried using ForAll but I don't quite know how to use it.

 

My objectives:

1) How to add all items from a Gallery to a collection? (I don't care about columns, I want all columns added but I don't know and don't care what they are and I'd prefer not to have to list them all out.)

2) Will the above solution guarantee that I'm only collecting the visible items in the Gallery and not the whole set of records fron Entity Name? My Gallery is filtered: 

 

Gallery.Items = Filter('Entity Name','Created by'.'Full Name' = User();'Full Name')

 

 

This is really doing my head in. Please and thank you to anyone who can help and much appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions

Hi GarethPrisk, 

 

Thank you for your response!

I actually fixed my issue earlier but my post got autoflagged as spam and I couldn't add my solution and close it.

I went with what you said as well, by changing my ClearCollect to 

 

ClearCollect(Collection, Filter('Entity Name','Created by'.'Full Name' = User();'Full Name'))​

I also had to update my Checkbox.Default value to

 

ThisItem.UniqueName in Collection.UniqueName

 

Everything works now.

View solution in original post

2 REPLIES 2
GarethPrisk
Resident Rockstar
Resident Rockstar

You mentioned you have a Gallery that is using a CDS entity as its source. I would propose that you collect values from CDS, using a replica of the Gallery's filter.

 

How are you controlling the rows in that Gallery?

  • Filter functions - easily replicated
  • Filter (CDS View) - easily replicated
  • Search - need to add a function to replicate how Search retrieves data from column(s)

 

Either way, you should have a good understanding of what is dictating the rows that are being shown in the gallery. Now you can apply that same filtering logic, for a Collect statement.

  • Simply: Collect ( Collection , {Identical Filtering as Gallery} )
  • Example: Collect( colCheckedItems, Filter ( cdsEntity , cdsColumn1 = filterValue, cdsColumn2 in searchValue ) )
  • This will be subject to delegation, and will get records up to X of your app's data row limit value

 

NOTE:

  • If you are showing a directly connected CDS entity, it will show you records which are able to be seen on the screen at the time
  • It will retrieve more records as you scroll the list, but not initially
  • If you expect that the total records (after all scrolling) will exceed your app's data row limit, then you may need to consider an alternate approach

Hi GarethPrisk, 

 

Thank you for your response!

I actually fixed my issue earlier but my post got autoflagged as spam and I couldn't add my solution and close it.

I went with what you said as well, by changing my ClearCollect to 

 

ClearCollect(Collection, Filter('Entity Name','Created by'.'Full Name' = User();'Full Name'))​

I also had to update my Checkbox.Default value to

 

ThisItem.UniqueName in Collection.UniqueName

 

Everything works now.

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (1,056)