cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
akharns
Level 8

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
mdevaney
Level 8

Re: Explicitly declared collections as a datasource for a gallery

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
Level 8

Re: Explicitly declared collections as a datasource for a gallery

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.
akharns
Level 8

Re: Explicitly declared collections as a datasource for a gallery

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.

mdevaney
Level 8

Re: Explicitly declared collections as a datasource for a gallery

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
akharns
Level 8

Re: Explicitly declared collections as a datasource for a gallery

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.

mdevaney
Level 8

Re: Explicitly declared collections as a datasource for a gallery

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

akharns
Level 8

Re: Explicitly declared collections as a datasource for a gallery

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

mdevaney
Level 8

Re: Explicitly declared collections as a datasource for a gallery

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

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 183 members 6,033 guests
Please welcome our newest community members: