Scenario: Need to display (in a gallery) a collection of Search Results based on Observations that are made by employees. Some employees are just employees, but others are Managers. Further, some are Location Admins. So, if Bob is a Location Admin of Area B AND a manager of Sally and Rick, then Bob can see a collection of his, Sally & Rick's, and everyone in Area B's Observations. (If Bob was just a manager, or just a location admin, then this would be easy. Because his employees may already be in the Location of which he's an admin, this is where it gets tricky. Any duplicates must be prevented or eliminated before displayed.)
First, use a routine that checks if the current user is a Location Admin. If yes, then populate a collection of Observation ID's based on that Location.
Something like:
ClearCollect(colObsID, ShowColumns(Filter('Observations',ObsLocation=varUserLocation), "ID"))
Next1, add all of the user's observations. (Just the ID for now.)
Something like:
Collect(colObsID, ShowColumns(Filter('Observations',Author.email=varUserEmail, "ID"))
Next2, determine if the user is a manager, then determine who are all the underlings.
Something like:
Set(gtblMyEmps, Filter('Employees',ManagerEmpID = gvarWorker.EmpID));
Set(gfWorkerIsManager, CountRows(gtblMyEmps) > 0);
Next3, Get the ID's of all of the underlings Observations.
Something like:
ForAll(gtblMyEmps, Collect(colObsIDSearchResults,
ShowColumns(
Filter('Observations', Author.Email = WorkEmail),
"ID")))
(I assume that this means: "Find matching records where gtblMyEmps.WorkEmail = Observations.Author.Email" (PLEASE LET ME KNOW IF IT DOESN'T!)
Next 4: Now that ObsID from multiple criteria have been added to this collection, it's time to strip it down and get the Unique Collection of the Last 2000 IDs.
Something like:
ClearCollect(colObsIDSearchResultsUnq,
FirstN(Sort(Distinct(colObsIDSearchResults,ID),
Result,Descending),2000));
FINALLY, use the collection of unique ID's to obtain a Distinct List of Observations for good ol' Bob. Something like:
ForAll(colObsIDSearchResultsUnq,
Collect(colObsSearchResults, Filter('Observations',ID = Result)));
This is the point where PowerApps produces the "Rate Limit Exceeded" error and fails to properly populate the colObsSearchResults collection.
What is the "proper" way to achieve the collection population of the Search Results, that Bob needs to see?
Please and Thanks.