Skip to main content
Community site session details

Community site session details

Session Id : 6ZDhZcjE/F6bCkA//eI4uc
Power Apps - Building Power Apps
Answered

Save info from nested gallery to a collection

Like (0) ShareShare
ReportReport
Posted on 13 Oct 2022 12:17:30 by 39

Hello,

 

 I am having trouble grabbing the data from a nested gallery and saving it to a collection.

 

I have a vertical gallery (Gallery1) and nested inside Gallery1 is a horizontal gallery (Gallery2). The data source for Gallery1 is a Sharepoint list and the datasource for Gallery2 is the attachments list for each item in Gallery1. Each item in Gallery1 can have any number of attachments.

 

Gallery2 displays the image and it's display name. I want to be able to save the all the images and display names for each attachments list for each item displayed in Gallery1.

 

I have a button when selected is supposed to collect the data and save it to a collection. The following is the code.

 

Clear(imageCollection);
Collect(imageCollection,
 ForAll(Gallery1.AllItems,
 {
 DataStream: Image.Image,
 Name: fileName.Text
 }
 )
);

 

 

Which gives me the following Collection:

Dmwolny_1-1665663196177.png

 

I have tried a number of different formulas with no success.  Please steer me in the right direction

 

 

Categories:
  • Dmwolny Profile Picture
    39 on 13 Oct 2022 at 15:05:39
    Re: Save info from nested gallery to a collection

    Thanks, you gave me something to chew on

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 13 Oct 2022 at 15:00:49
    Re: Save info from nested gallery to a collection

    @Dmwolny 

    Well, the main point of my response was that your gallery has the data.  So duplicating into a collection is just that..a duplication.

     

    In other words:

    ClearCollect(someCollection, <theFormulaIprovided>);
    someFlow.Run(JSON(someCollection))

    This would be duplicating the data to then convert to JSON.

     

    Whereas:

    someFlow.Run(JSON(<theFormulaIprovided>))

    Is equivalent and does not duplicate unnecessarily.

     

  • Dmwolny Profile Picture
    39 on 13 Oct 2022 at 14:57:28
    Re: Save info from nested gallery to a collection

    Thank you Randy, that did the trick.

     

    Ultimately I want to send out an email with the all the data from Gallery1 including all of the attachments. I have a Flow that accepts a JSON and then compiles the JSON into an email. I wasn't sure how to nest the attachments into a Collection to send out as a JSON.

     

    I wanted to split the data into 2 collections, 1 with strings and second with the image data. Perhaps there is a more elegant way to accomplish this.

  • Verified answer
    RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 13 Oct 2022 at 14:45:15
    Re: Save info from nested gallery to a collection

    @Dmwolny 

    Your gallery already contains all of your data!!  Putting it in a collection is just duplicating the data you already have.

     

    But if there is some particular reason to duplicate it, then please consider changing your Formula to the following:

    ClearCollect(imageCollection,
     Ungroup(
     ForAll(Gallery1.AllItems,
     ForAll(Gallery2.AllItems,
     {DataStream: Image.Image,
     Name: fileName.Text
     }
     )
     ),
     "Value"
     )
    );

     

    There is one caveat to this...nested galleries (Gallery2) do not naturally give up their AllItems tables.  You need to force the primary gallery to invoke data from the nested gallery.  To do this, place a label in your parent gallery and set the Text property to: CountRows(Gallery2.AllItems)  

    You can make the label hidden...it just needs to exist to "invoke" the reveal of the gallery.  That formula does not have to be based on AllItems, it can reference anything in the gallery, but I find the above simple enough.

     

    I hope this is helpful for you.

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 1