cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MeSan
Helper III
Helper III

Get only checked elements of a gallery

Hello everyone,

 

I have a gallery which associated with an SQL table "Persons", Inside I have a checkbox for each element. How can I get all the checked element of this gallery please ? I'm struggling to find a way.. I used the "concat" function but did not work.

 

Thanks in advance !

1 ACCEPTED SOLUTION

Accepted Solutions
CNT
Super User
Super User

@MeSan Try this,

Clear(colSelectedPersons);
ForAll(yourGallery.AllItems, 
    If(ThisRecord.yourCheckBox.Value=true, Collect(colSelectedPersons, {PersonID: ThisRecord.PersonID})
)

Here we are iterating through the gallery and collecting the PersonID (as an example, you can change it to whatever you have) of the selected Persons.

 

Hope this helps!

View solution in original post

10 REPLIES 10
CNT
Super User
Super User

@MeSan Try this,

Clear(colSelectedPersons);
ForAll(yourGallery.AllItems, 
    If(ThisRecord.yourCheckBox.Value=true, Collect(colSelectedPersons, {PersonID: ThisRecord.PersonID})
)

Here we are iterating through the gallery and collecting the PersonID (as an example, you can change it to whatever you have) of the selected Persons.

 

Hope this helps!

Hello @CNT 

Thanks for this suggestion I'll try it, but I have a question plz is this a collection you're using to store values ?

This is my first time working with collections, and I don't understand where does the "colSelectedPersons" come from.. Is it a collection you've created somewhere ? And how do I get the its value that englobes all the selected items of the gallery ?

 

Thanks !

@MeSan Glad you asked! Yes, Collections are a temporary storage in the App where you can collect all kind of data that you want to use during the lifetime of the App. In my example, Clear(colSelectdPersons) basically creates and clears that collection ready to add values to it. Inside the FollAll we are checking if the checkbox is selected and if so, we are adding it to our collection. Later, you can use the values in this collection to Patch your SQL db.

@CNT , Nice thanks. So where do I need to insert the above formula ? 

I'm putting it in a Label control in the Text property to test but didn't work..

@MeSan To test it put it in the OnSelect of a button and click on the button and then goto View -> Collections to see the contents of the collection (it will show the first 5 values as a sample),

CNT_0-1622464342770.png

 

@CNT Okey, what if I want to get the content of the collection is there a function that does this ?

Thanks !

@MeSan You can get the contents of the collection in different ways, For example you could out it in a ForAll loop,

ForAll(colSelectedPersons, 
   ThisRecord.Value // This will give the value of the current record
)

 

If you share some formulas you have and what you want to achieve, we can find a way to use this collection to reach your goal!

@CNT I actually wanna get all the elements (I wonder if "concat" can be used here), for some reason the expressions Clear and Collect, ForAll doesn't work for me.. It tells me the identifier isn't recognized ..

Any solution please ?

@MeSan This will give you a variable gblSelectedPersons with the concatenated values (separated by semicolon),

Set(gblSelectedPersons, Concat(colSelectedPersons, ThisRecord.Value, ";"))

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (2,859)