I believe I came up with a solution for my follow-up collection problem that works out well. With a mix of collections, lookup, and variables I am able to filter a second gallery by a field in the many-to-many related entity featured on the first gallery.
Eg: Entity1 on Page1 has a gallery called "Gallery1." Entity1 has a many-to-many relationship with Entity2. I want to select a record of Entity1 in “Gallery1” and travel to Page2, where I will see a gallery of Entity2 that is filtered by the records in Entity2 that are related to the record of Entity1 that I selected on Page1. In other words, if Entity1 is Categories and Entity2 is Books, I would select a category and on the next page see a list of books that pertain to the selected category. The following code is how I achieved this:
The “Items” property of Gallery1:
Entity1;
The “OnSelect” property of Gallery1:
Select(Parent);
Set(variable, ThisItem.Entity1GUID);
ClearCollect(myCollection, LookUp([@Entities1], Entity1GUID = variable).Entities2);
Navigate(Page2);
The “Items” property of Gallery2:
myCollection;
And there you have it! My follow-up question is solved!
Now, I still can’t figure out how to answer my original question. Originally, I wanted a gallery for Entity2 filtered by a field value in Entity2. The gallery I want to filter is on my home screen, but cannot get it to work. Right now I have created a collection that has all of the GUID’s of the records in Entity2 that meet my field value I want to filter by. I want to get the Entity2 record, and tried the following in the OnVisible property of the home screen, but it didn’t work:
ClearCollect(collection1, Filter([@Entities1], ‘Filter Field’ = ‘Filter Field (Entities1)’.No).Entity1GUID);
ClearCollect(collection2, Entity2);
ClearCollection(collection2, ForAll(collection1, LookUp([@Entities1], Entity1GUID in collection1).Entities2));
Then the “Items” property of my gallery is the following:
collection2;
This doesn’t work, and I feel like there is something so simple I’m just not getting here. If anyone has any idea what to do to solve my original problem, please let me know.
Thanks!
-----------------------------------------------------------------------------------------------------------------------------------------------
EDIT: My proposed solution in the first half actually doesn't work. I don't need to make the collection, so remove the "ClearCollect" line from the "OnSelect" property of Gallery1. Then, just set the "Items" property of Gallery2 to:
LookUp([@Entities1], Entity1GUID = variable).Entities2
This seemed to work and pass in all of the information about Entity2. Not sure why making a collection doesn't work, but at this point it doesn't matter.