cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

Explicitly declared collections as a datasource for a gallery

Is it possible to explicitly declare a collection and use it as the data source for a gallery?  When I try, it acts as if I don't have a data source.  I can't add fields and it finds no rows.  In my test app, I'm using the following under the Items property of my gallery:

ClearCollect(CollectionX,{dummyfield:"x"})

 

I think that creating the collection under items creates a temporary collection (which means I shouldn't be creating a collection name that isn't linked to the data source), but I haven't found the syntax that allows me to define the records in such a way that they are recognized as a data source.

 

I'm thinking that perhaps the collection needs to already exist so I can select it for this gallery.  Where would I put it, then?  I already have code in the app's On Start property.  And how could it serve as a data source for the gallery?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Oh, you can totally declare as many functions as you want in the same property. To do this separate the statements by semi-colons. Try putting this code into the OnVisible property:

ClearCollect(CollectionX,{dummyfield:"x"});
ClearCollect(CollectionY,{dummyfield:"y"});
ClearCollect(CollectionY,{dummyfield:"z"});

As you can imagine the semi-colon works with all PowerApps functions allowing you to chain together several functions and create more complex apps.

Hope I answered your question!

View solution in original post

7 REPLIES 7
Highlighted
Super User III
Super User III

There’s nothing wrong with your code. You just can’t put it directly into Items. Instead, put your code in the OnSelect property for a button

ClearCollect(CollectionX,{dummyfield:"x"})

And then put the Collection into the Items property of your gallery

CollectionX

The general concept here is that you can only change a collection using a behaviour based property such as OnSelect, OnSuccess, OnVisible, etc. It is not possible to manipulate collections in non behaviour properties such as Items, Default, Text, etc.

—-
Please Accept As Solution if this post answered your question so others can find it more quickly. If you found this post helpful consider giving it a Thumbs Up.
Highlighted

So the user has to push the button to see the info?  There ought to be a way to make it happen without user action.

Highlighted

You can put the code in the OnVisible property of the screen instead.

ClearCollect(CollectionX,{dummyfield:"x"})

My example of using the OnSelect property of the button was just for demonstration. The simplest rule to remember is you can use the function ClearCollect() if in any property starting with the word “On”.

—-
Please Accept As Solution if this post answered your question so others can find it more quickly. If you found this post helpful consider giving it a Thumbs Up
Highlighted

Ok, just one more question then:   There aren't very many places to create collections then.  Is there a way to declare more than one collection in one place?  Otherwise, I am severly limited on how many collections I can declare.

Highlighted

Oh, you can totally declare as many functions as you want in the same property. To do this separate the statements by semi-colons. Try putting this code into the OnVisible property:

ClearCollect(CollectionX,{dummyfield:"x"});
ClearCollect(CollectionY,{dummyfield:"y"});
ClearCollect(CollectionY,{dummyfield:"z"});

As you can imagine the semi-colon works with all PowerApps functions allowing you to chain together several functions and create more complex apps.

Hope I answered your question!

View solution in original post

Highlighted

Perfect.   Now I am happy.  Thanks for all your help.

Highlighted

@akharns
Awesome, have a blast with those new collection techniques!

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (7,434)