Forum Discussion

ADumith's avatar
ADumith
Iron Contributor
Apr 15, 2022

Collection not populating

Hello, first of all I want to apologize if what I am going to ask is very silly, but in reality it is the first time that I deal with PowerApps, I love this platform but I am still learning.

 

My problem is, I have a list of employees EmployeesDirectory and this list of calls contains information of the employees such as the day of the birthday, these fields (day, month and year) are of a single line text type.

 

I am building an application in PowerApps where I want to show the birthdays of the month, then I must filter my list by the month field called Mbirth and then order the records by day field called Dbirth, so I can show the list of people who have birthdays that month.

 

I have managed to connect the SharePoint list with the apps and the records are displayed, but reading I understand that it's better to use collections and configure the data source property of the gallery with the collection.

 

I have tried placing the code in OnVisible (Screen) and also in OnStart (App) but it doesn't work.

 

Set(varMonths, Text(Today(),"mm"));
ClearCollect(colBirthDay,Filter(EmployeesDirectory,Mbirth=varMonths));

 

But my problem is that the collection is not only not filled, even when I go into the properties I see some fields that are not the fields of my list.

 

Can anyone give me any suggestions as to what might be going on?

 

I put the code of the filter and the images of the collection.

 

Thank you very much, I hope you can help me.

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

     

     

     

  • jonlake's avatar
    jonlake
    Iron Contributor

    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.

    • ADumith's avatar
      ADumith
      Iron Contributor

      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.

       

       

      • jonlake's avatar
        jonlake
        Iron 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.

         

Resources