web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Bug creating collectio...
Power Apps
Unanswered

Bug creating collection using ForAll and ThisRecord

(1) ShareShare
ReportReport
Posted on by 216
To create a collection for my data export, I use the following code:
//Create a collection for the data export
ClearCollect(colExportActions, {});
ForAll(GalleryAllActions.AllItems, Collect(colExportActions, {LinkedChange: ThisRecord.LinkedChangeGal.Text, Title: ThisRecord.Title4_2.Text, ActionOwner: ThisRecord.Owner.Text, ActionType: ThisRecord.TypeOfAction.Text, TargetCloseDate: ThisRecord.TargetCloseDate.Text, Status: ThisRecord.ButtonActionStatus.Text}));
RemoveIf(colExportActions, IsBlank(Title));
However, I noticed that the export was missing data from further down in the export - all the columns except the Title were displaying as blank. If I scroll down the gallery to view all items before clicking on my export button, then I don't have this issue and I get all data.
I can see that the collection itself is not showing all the data.
 
From other posts it looks like using ThisRecord in a ForAll can be buggy - is there another way I could write this?
 
It had been working fine on this one app until recently. Another app uses the same code structure without any issues.
Categories:
I have the same question (0)
  • Pstork1 Profile Picture
    68,678 Most Valuable Professional on at
    Bug creating collection using ForAll and ThisRecord
    I don't think the problem here is the ForAll(). The issue arises from the fact that a Gallery is a paged interface to a filtered data source. By design the gallery only contains 100 items when you first load it.  When you scroll down to look at item 101 it will load the next 100 and so on until the gallery contains all the items in the filtered data source.  This behavior is why your code works when you scroll through the gallery first. There's no way to avoid it because that's the way the gallery is designed to work.  You could use the same code and replace the Gallery.AllItems with whatever is in the Items property of the Gallery. That is the filtered data source that the gallery is paging through.

    ----------------------------------------------------------------------------------
    If this Post helped you, please click "Does this answer your question" and give it a like to help others in the community find the answer too!

    Paul Papanek Stork, MVP
    Blog: https://www.dontpapanic.com/blog
     
  • CAlvy Profile Picture
    216 on at
    Bug creating collection using ForAll and ThisRecord
    Thanks @Pstork1. But this doesn't explain why it works fine exporting from another gallery with over 1000 rows. Or why it's still bringing across the Title.
     
    I have filters and search on my gallery so I would need to apply those same filters to the data source first. I wanted to avoid that approach, but if there's no other way I'll try that.
  • Suggested answer
    WarrenBelz Profile Picture
    152,841 Most Valuable Professional on at
    Bug creating collection using ForAll and ThisRecord
    Hi @CAlvy
    To add to the suggestion (@Pstork1 is correct concerning the 100 item initial gallery load, so you will be missing records if the gallery is bigger than this and the user has not scrolled down past this) also try the As disambiguation operator instead
    ForAll(
       Filter(
          GalleryAllActions.AllItems,
          !IsBlank(Title)
       ) As _Data, 
       Collect(
          colExportActions, 
          {
             LinkedChange: _Data.LinkedChangeGal.Text, 
             Title: _Data.Title4_2.Text, 
             ActionOwner: _Data.Owner.Text, 
             ActionType: _Data.TypeOfAction.Text, 
             TargetCloseDate: _Data.TargetCloseDate.Text, 
             Status: _Data.ButtonActionStatus.Text
          }
       )
    );

    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee

     
  • Verified answer
    CAlvy Profile Picture
    216 on at
    Bug creating collection using ForAll and ThisRecord
    Thanks for the suggestion @WarrenBelz. I updated the code but had the same issue.
     
    I figured it could be to do with one of the app settings. After I turned off the 'New analysis engine' setting and reloaded my app, it seems to be working fine again now. Must be a bug there.
     
    Thank you both for your help though.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 836 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 231 Super User 2025 Season 2

Last 30 days Overall leaderboard