cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
akharns
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

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
mdevaney
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.

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.

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

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.

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

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

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

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (26,039)