web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Bad habits and combini...
Power Apps
Answered

Bad habits and combining the OnVisible and the Items question

(0) ShareShare
ReportReport
Posted on by 219

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}
 )
 )
)

 

Categories:
  • sasrsc1966 Profile Picture
    219 on at

    I've made some progress this works.... all placed in the gallery.items property...

    SortByColumns(
     Filter(
     ForAll(
     Filter(
     'Ticket Request',
     (Requestor.Email = varUser.Email || Recipient.Email = varUser.Email || 'Executive VP'.Email = varUser.Email)
     ) 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
     }
     )
     )
     )
     ),
     If(
     DrpDates_2.Selected.Value = "All Time",
     true,
     EventDateTime >= Now()
     ) && If(
     IsBlank(InpEventName_3.Text),
     true,
     InpEventName_3.Text in EventTitle
     ) && If(
     DrpVenues_3.Selected.Title = "*** All Venues ***",
     true,
     DrpVenues_3.Selected.Title = Venue
     ) && If(
     DrpEventTypes_3.Selected.Title = "*** All Event Types ***",
     true,
     DrpEventTypes_3.Selected.Title = EventType
     ) && If(
     DrpCapacityStatus_2.Selected.Value = "All Status",
     true,
     DrpCapacityStatus_2.Selected.Value = Status
     )
     ),
     "EventDateTime",
     Descending
    )

    My remaining challenge is to add this so I can do alternating row colors... I'm just not sure how to affix it as this needs to be added AFTER all the filtering is done. Suggestions welcome please... I've been at this for hours and while I'm pleased at my progress I want to cross it off 😉

    ForAll(
     Sequence(CountRows(records)),
     Patch(
     Last(
     FirstN(
     records,
     Value
     )
     ),
     {RowNo: Value}
     )
     )



  • Verified answer
    sasrsc1966 Profile Picture
    219 on at

    I guess if you work on it long enough you can do it - in some ways. This works - does anyone thing this is an inefficient way and hence has a better suggestion...

    With(
     {
     records: SortByColumns(
     Filter(
     ForAll(
     Filter(
     'Ticket Request',
     (Requestor.Email = varUser.Email || Recipient.Email = varUser.Email || 'Executive VP'.Email = varUser.Email)
     ) 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
     }
     )
     )
     )
     ),
     If(
     DrpDates_2.Selected.Value = "All Time",
     true,
     EventDateTime >= Now()
     ) && If(
     IsBlank(InpEventName_3.Text),
     true,
     InpEventName_3.Text in EventTitle
     ) && If(
     DrpVenues_3.Selected.Title = "*** All Venues ***",
     true,
     DrpVenues_3.Selected.Title = Venue
     ) && If(
     DrpEventTypes_3.Selected.Title = "*** All Event Types ***",
     true,
     DrpEventTypes_3.Selected.Title = EventType
     ) && If(
     DrpCapacityStatus_2.Selected.Value = "All Status",
     true,
     DrpCapacityStatus_2.Selected.Value = Status
     )
     ),
     "EventDateTime",
     Descending
     )
     },
     ForAll(
     Sequence(CountRows(records)),
     Patch(
     Last(
     FirstN(
     records,
     Value
     )
     ),
     {RowNo: Value}
     )
     )
    )

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 402 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 296 Most Valuable Professional

Last 30 days Overall leaderboard