cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate I
Advocate I

Iterate through a Galleries list

I have a gallery that shows a history of activites for a contact.  When you click on a history activity it brings you to the details screen.  Right now the details screen Form is bound to the Galleries.selected property.  I'm trying to be able to give the user controls on the detail form to go to the next / previous record in the Gallery, without going back to the Gallery.  Is there an index exposed that you can access these items like in a Collection or Dictionary?

8 REPLIES 8
Highlighted
Power Apps
Power Apps

Re: Iterate through a Galleries list

 

PowerApps does not support random access into any tabular data sources (something akin to "array accesses"). The closest pattern that one could use to reference a specific row in a collection, is a lookup with respect to a specific field that uniquely identifies that row. The field could be numeric, and it could in fact even be 0-based like the type of index you are hinting at:

 

    CustomerId  Name

    0             Bob

    1             Alice

    2             Mary

 

= LookUp(Customers, CustomerID = desired_index_here)

 

Your extension that allows navigation back and forth would have to maintain this state (for example a CustomerID, in a context variable), and to either (1) drive gallery selection using it, in a way similar to the above; which will in turn drive the form, or (2) bind the form directly to something like the above:

 

    Form1.DataSource = Customers

    Form1.Item = LookUp(Customers, CustomerID = currentCustomerID)

    NavBackButton.OnSelect = UpdateContext({ currentCustomerID: currentCustomerID - 1 })

    NavForwardButton.OnSelect = UpdateContext({ currentCustomerID: currentCustomerID + 1 })

 

I hope this helps.

Radu Gruian [MSFT] ** PowerApps Staff
Highlighted
Advocate I
Advocate I

Re: Iterate through a Galleries list

It does but my data source does not have a field like that.  This list is would be around 50 items out of 300000+.  Unless you can copy the filtered data to a temp table or collection and add an autonumber column to index it I don't think this can work yet.

 

Thanks

Highlighted
Power Apps
Power Apps

Re: Iterate through a Galleries list

What back end are you using to store your data? Can you add a computed column on the server side that gives you the "index" ?

Radu Gruian [MSFT] ** PowerApps Staff
Highlighted
Advocate I
Advocate I

Re: Iterate through a Galleries list

My backend is a SQL server but its the main table in my on-prem CRM app.  I could add this as an index but I'd rather not since the CRM application itself is a little shaky to begin with.

Highlighted
Community Champion
Community Champion

Re: Iterate through a Galleries list

Hi rgruin:

 

I have learnt your iteration. Thanks.

 

However, I wish to share my thought on that.

If you BACK and NEXT beyong the CustomerID, the action will never resume.

I will tried on following condition based on CDM RecordId.

Say: 112233, 112234, 112235, 112236,..., 112250

On BACK, it may go to 112232, no record found. Even press NEXT again, it will increment NOT goto 112233.

On NEXT, it may go to 112251, no record found, and even pressing BACK again, it will NOT goto 112250.

 

Hence, I would suggest to include a validation of if it has hit Max(RecordId) and and stop UpdateContext.

 

Hope I am wrong, NOT right!

hpkeong
Highlighted
Power Apps
Power Apps

Re: Iterate through a Galleries list

 

Of course. Please do include as much validation as needed to ensure that your back/forward navigation stays within the appropriate bounds. My formulas were for reference only, so I needed them to be as simple as possible so they could be easily understood. I don't know what your specific scenario is, but feel free to make use of e.g. LookUp to detect whether the previous/next record actually exists -- before decrementing/incrementing the ID, respectively.

 

For example:

 

    BackButton.OnSelect = If(!IsBlank(LookUp(Customers, CustomerID = customerId - 1)), UpdateContext({ customerId: customerId - 1}))

    FwdButton.OnSelect = If(!IsBlank(LookUp(Customers, CustomerID = customerId + 1)), UpdateContext({ customerId: customerId + 1}))

 

Additionally, you may want to disable the Prev/Next buttons when you reach the bounds, so you can't even go past either of them:

 

    BackButton.Disabled = IsBlank(LookUp(Customers, CustomerID = customerId - 1))

    FwdButton.Disabled = IsBlank(LookUp(Customers, CustomerID = customerId + 1))

 

Also, make sure that your customerId variable is properly initialized to begin with.

 

Radu Gruian [MSFT] ** PowerApps Staff
Highlighted
Community Champion
Community Champion

Re: Iterate through a Galleries list

Hi rguin:

 

Yes, appreciate very much of the validation which are what I mean.

Thanks for sharing and I am very sure that will help many.

 

Have a nice day.

hpkeong
Highlighted
Advocate IV
Advocate IV

Re: Iterate through a Galleries list

Is there any way to index from powerapps studio through a column that contains the values (1,2,3,4,5, etc)?.

The fact is that I already have a table indexed from CDM.
But when filtering it, the RecordId values remain discontinuous. For example:

{{RecordId: 112230}, {RecordId: 112231}, {RecordId: 112235}, {RecordId: 112236}, {RecordId: 112240}, etc.}...

We need the AddColumnIndex formula!!... Thank you and I await your response...

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Robotic Process Automation

Let's talk about the solution provided by Microsoft for Robotic Process Automation (RPA)

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (10,779)