cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Alv_gc
Regular Visitor

Toggle on/off to add/remove record from a Collection

Hi all 😁

 

I have started recently using PowerApps so my questions are very basic.

 

I have a Gallery with a list of countries that I would like to be able to select/unselect and those selected countries to be saved in a Collection so I can use them for other purposes.

I have added a "Toggle" with the following logic:

- If on I want that country to be stored in the collection.

- If off I want that country to be removed from the collection.

 

In the Toggle Properties I have:

- OnCheck: Collect(CollectionName,{Country: LabelCountry.Text})

- OnUncheck: Remove(CollectionName,ThisItem)

 

"OnCheck" works perfectly but not the "UnCheck" as it brings an error message saying that the Item is not compatible with the collection...

 

Thank so much!

 

Al.

1 ACCEPTED SOLUTION

Accepted Solutions
mdevaney
Super User
Super User

@Alv_gc 

You are very close!  I believe you just need to add "ThisItem" to the OnCheck property code you already have

 

OnUnCheck: Remove(CollectionName, LookUp(CollectionName, ID = ThisItem.ID))

 

Note:  my assumption is LabelCountry exists within each gallery row.

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

2 REPLIES 2
mdevaney
Super User
Super User

@Alv_gc 

You are very close!  I believe you just need to add "ThisItem" to the OnCheck property code you already have

 

OnUnCheck: Remove(CollectionName, LookUp(CollectionName, ID = ThisItem.ID))

 

Note:  my assumption is LabelCountry exists within each gallery row.

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

eka24
Super User
Super User

OnUncheck try this (Replace ID with your actual column ID name):

If(ThisItem.ID exactin CollectionName.ID,
Remove(CollectionName, LookUp(CollectionName,ID=ThisItem.ID)))
 
 

If you like this reply, please give kudos. And if this solves your problem,
please accept this reply as the solution.

Helpful resources

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

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (3,386)