Forum Discussion
Collection not populating
- Apr 18, 2022
Hi ADumith , I downloaded and imported your app. I refreshed the source data to be my SP list and used the collection and filter elements I've shared and it seems to work fine. I would encourage annotating references wherever possible.
My SP list is structured like this:
My date source in the app is targeted at the list:
The 'OnStart' property is set to:
The gallery items is set to:
The first of your gallery fields is set to:
The second of your gallery fields is set to:
Without access to your source list I'm unsure what may be wrong at your end. I can use your app, redirect it and modify a few of the field names/targets and it appears to be working.
Hi ADumith , I built a quick solution to demonstrate how you can achieve this. First I built a simple SP list:
I built a simple app and set the 'on start' property to this:
//set a variable to the current month
Set(varMonth, Text(Now(),"mm"));
//create a collection of all eployee records in ascending order by mbirth
ClearCollect(colBirthDay, Sort(EmployeesDirectory,month_of_birth,Ascending));
I then set the gallery items property to this:
//filter the gallery items to only show those with a birth month matching the current month
Filter(colBirthDay,month_of_birth=varMonth)
You would likely be better off converting the date of birth to a month item and filtering on the result rather than have a dedicated field in your list. Less to input and less to go wrong.
Hello!jonlake
Thank you very much for continuing to help me.
I already managed to get the collection to load data. Goal achieved.
But the records are still not displayed in the gallery. The data source is the collection, and the fields are properly mapped, in fact when I place only the collection the data is shown, but when placing the filter none is shown.
Without filter
Filtering.
Create a new collection to test and the behavior is the same.
Why the filter does not work?
Thanks again.
- jonlakeApr 18, 2022Iron Contributor
Hi ADumith, I recommend adding a button to test, just in case closing and restarting the app doesn't force the 'on start' setting of the variable. Something like this:
If that doesn't test the population of the gallery I would check the format and content of the month field in your SP list. I've attached a version of the test app I've built. Simply redirect to you SP list.
- ADumithApr 18, 2022Iron Contributor
Hello jonlake
I realized why the collection sometimes doesn't populated, when that happens I just save the app, close PowerApps and go back in.
The Dbirth and Mbirth fields are fields of type Single line of text.
It is possible to create a filtered and ordered collection at the same time and thus in the gallery I only map to the collection. What do you think about the idea?
By the way, thanks for sending me the app but due to security policies I can't upload it to our platform.
Thanks again,
- jonlakeApr 18, 2022Iron Contributor
Hi ADumith , you can do it at the gallery items level:
//filter the gallery items to only show those with a birth month matching the current month
Sort(Filter(colBirthDay,month_of_birth=varMonth),date_of_birth,Descending)In my previous responses I've mentioned the Onstart action, which creates a sorted (but not filtered) collection:
//create a collection of all employee records in ascending order by mbirth
ClearCollect(colBirthDay, Sort(EmployeesDirectory,month_of_birth,Ascending));