cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
carem
Level: Powered On

Can't create Collection using ClearCollect Function

I encountered a challenge when following the guidelines of this article.
In the Step: Writing the related schools into a collection

Faculty Field -> OnChange: 

ClearCollect( collSchools, { Schools: Filter( Schools, Faculty.Value = DataCardValue2.Selected.Value ) } )

Property Explanation

collSchoolsThis is our collection where all related schools for the selected faculty are written in to
SchoolsThis is the name of the column where the data is written in to
FilterThis is the function that filters values from a data set. The format of this function is as follows: Filter(source,logical_test)
SchoolsThis is the data set that we use in our filter. In this case, it is the Schools list we added as data source
Faculty.ValueThis is the value we are looking for in our data set. In this case, it is the Faculty lookup field in our Schools list
DataCardValue2.Selected.ValueThis is the selected faculty from our PowerApp

 

I follow this fomulas but the result is an empty collSchools Collection.

Here is my Form Setting

Screen Shot 2019-10-08 at 9.17.34 PM.png

And the OnChange of Faculty Dropdown:

Screen Shot 2019-10-08 at 9.18.52 PM.png

And the collSchools Collection: Empty School Column

Screen Shot 2019-10-08 at 9.19.26 PM.png

Can anyone help me resolve this problem?

11 REPLIES 11
Highlighted
Dual Super User
Dual Super User

Re: Can't create Collection using ClearCollect Function

DataCardValue2 is an arbitrary name provided by the system when you added the data card to the screen.  But in your image it shows you've renamed it to drpd_Faculty.  So the formula should read.

ClearCollect( collSchools, { Schools: Filter( Schools, Faculty.Value = drpd_faculty.Selected.Value ) } )

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
carem
Level: Powered On

Re: Can't create Collection using ClearCollect Function

@Thanks for the quick answer, @Pstork1.

But my setting is correct as you. You can see the picture I setting.

Dual Super User
Dual Super User

Re: Can't create Collection using ClearCollect Function

Are you sure that fields in the Schools list match (including case sensitivity) the entries in the Faculty dropdown list?  The collection is being created it just has no data in it.  So I suspect your filter statement is returning an empty record set.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
carem
Level: Powered On

Re: Can't create Collection using ClearCollect Function

Here is my Schools List. And I see everything match the setting in PowerApps (including case sensitivity)

Screen Shot 2019-10-08 at 9.46.44 PM.png

Dual Super User
Dual Super User

Re: Can't create Collection using ClearCollect Function

Try this for a quick test.  Replace the current statement with the following:

 

ClearCollect( collSchools, { Schools: Filter( Schools, Faculty.Value = "Faculty of Health" ) } )

See if that provides a collection.  YOu could also temporarily add a gallery to your form and set the Items collection to the following to make sure that you are getting a set of records back.

Filter( Schools, Faculty.Value = "Faculty of Health" )

I still think something has to be off in your Filter statement.

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
carem
Level: Powered On

Re: Can't create Collection using ClearCollect Function

I follow your instruction and have the result:

1/ Can't create a collection

2/ Can create a Gallery with 

Filter( Schools, Faculty.Value = "Faculty of Health" )

But it default display the Created By Column and ignore the Faculty Column.

Screen Shot 2019-10-08 at 10.02.32 PM.png 

What can I do next?

Dual Super User
Dual Super User

Re: Can't create Collection using ClearCollect Function

Hi @carem 

 

Create a label for test purpose

Set text property of label to

 

CountRows(Filter( Schools, Faculty.Value = DataCardValue2.Selected.Value ))

 

If count is 0, then your query is not correct

 

also try with 

CountRows(Filter( Schools, Faculty.Value = "hardcode a value here and check" ))

 

--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

Dual Super User
Dual Super User

Re: Can't create Collection using ClearCollect Function

It doesn't matter what shows in the Gallery.  The whole point was to make sure the filter works to return records.

 

If you take the other formula and put it in the OnSelect for a button then run the app and press the button do you get a collection?



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
carem
Level: Powered On

Re: Can't create Collection using ClearCollect Function

@RezaDorrani 

I set 2 text labels to test your expression.

And both of them return 0.

Screen Shot 2019-10-09 at 10.03.03 AM.png

The warning:

Screen Shot 2019-10-09 at 10.03.49 AM.png

That means my query was wrong. But I couldn't detect any points.

 

@Pstork1 

I try the example of Microsoft:

ClearCollect( IceCream, { Flavor: "Strawberry", Quantity: 300 } )

and success.

Screen Shot 2019-10-09 at 10.08.23 AM.png

 

And I have discovered a serious problem with Preview Mode. I think it is the cause of this problem.

My Preview Function is not working. It's mean when I press F5 you can see my form like this:

Screen Shot 2019-10-09 at 10.20.31 AM.pngEdit ModeScreen Shot 2019-10-09 at 10.20.24 AM.pngPreview Mode

It may be that it cannot recognize the value of drpd_Faculty.Selected.Value. And return an empty Collection.
Follow Pstork1's advice, I create a button with OnSelect Property:

ClearCollect( collSchools, { Schools: Filter( Schools, Faculty.Value = "Faculty of Health" ) } )

And it's work.

But when I go back for  

ClearCollect( collSchools, { Schools: Filter( Schools, Faculty.Value = drpd_Faculty.Selected.Value ) } )

It does not work anymore.

Helpful resources

Announcements
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (8,418)