As I improve my Power App skills one thing I find I have a tendency to do is use the onVisible to build collections. This is fine in certain instances, but I think @WarrenBelz or @RandyHayes got me thinking about this some more. What happens if the page stays visible but the collection has changed on the page?? Normally I do lots of code in the onVisible to help make the Gallery.Items easier which will reference a collection I built in the onVisible. I'm just a citizen dev so some of the concepts I'm still grasping. In my current case I display a gallery of items and in the gallery I have an action item that changes a value in a row but that is not reflected unless I leave the page and come back in - as the onVisible kicks in. I'm mentioning this because I think other novices like me will fall into this "potentially" bad practice. Feel free to dispute what I'm saying.
So I want to combine the onVisible and the Items into the Gallerys.Items property.... (sorry this is long)
onVisible:
ClearCollect(
MyRequests,
With({ req: Filter('Ticket Request',Requestor.Email=varUser.Email || Recipient.Email=varUser.Email || 'Executive VP'.Email=varUser.Email)},
ForAll(
req As _r,
With(
{
_e: LookUp(
Events,
ID = _r.EventId
),
_t: LookUp(
'Request Status',
ID=_r.TicketStatusId,Title)
},
With(
{
_v: LookUp(
Venues,
ID = _e.VenueId,
Title
),
_et: LookUp(
'Event Types',
ID=_e.EventTypeId,Title)
},
Patch(
_r,
{
EventTitle: _e.Title,
EventDateTime: _e.'Event Date and Time',
Venue: _v,
Status: _t,
EventType: _et
}
)
)
)
)
))
Then the Items currently is...using MyRequests as the foundation...The filters in this can only be applied after MyRequests are formed as I need those values above in the subsequent if then filters below. I've been playing with this for a few hours and you know how a comma in the wrong place will get you... getting frustrated...
With(
{
records: SortByColumns(
Filter(
MyRequests,
If(DrpDates_1.Selected.Value="All Time",true,EventDateTime >= Now()) &&
If(
IsBlank(InpEventName_2.Text),
true,
InpEventName_2.Text in EventTitle
) && If(
DrpVenues_2.Selected.Title = "*** All Venues ***",
true,
DrpVenues_2.Selected.Title = Venue
) && If(
DrpEventTypes_2.Selected.Title = "*** All Event Types ***",
true,
DrpEventTypes_2.Selected.Title = EventType
) && If(DrpCapacityStatus_1.Selected.Value="All Status",true,DrpCapacityStatus_1.Selected.Value=Status)
),
"EventDateTime",Descending
)
},
ForAll(
Sequence(CountRows(records)),
Patch(
Last(
FirstN(
records,
Value
)
),
{RowNo: Value}
)
)
)