cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ryanb1
Level: Powered On

Remove collection item based on gallery check mark

I have a gallery which collects items when the user checks the check box (copying this tutorial by @vasavib . The code below (which is on the OnCheck property of the checkbox) specifies that if the item is already checked when the users checks it, the item is removed from the collection rather than adding it.

 

My issue is that the item is not being removed from the collection (CheckedItems) in that scenario. What do I need to change? Thanks in advance.

 

Nb. I have used the same names as the tutorial: ChecklistItemsSource and CheckedItems.

 

 

 

If(
    !IsBlank(
        LookUp(
            CheckedItems,
            ID = ThisItem.ID
        )
    ),
    Remove(
        CheckedItems,
        ThisItem
    ),
    Collect(
        CheckedItems,
        ThisItem
    )
)

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ryanb1
Level: Powered On

Re: Remove collection item based on gallery check mark

Thanks for the suggestion but it didn't work. 

 

In the end I went for the solution described in this video where the appropriate fields are saved into a collection in the OnCheck property; then onselect for a button saves that collection to the datasource. OnUncheck removes the item by finding the first item that matches the filter.

View solution in original post

6 REPLIES 6
Eelman
Level 10

Re: Remove collection item based on gallery check mark

@ryanb1 

Try RemoveIf instead of Remove, like this

 

RemoveIf ( CheckedItems, ID = ThisItem.ID )

 

Also, do all items in CheckedItems have IDs ie they all come from a data source, like SharePoint? Any newly created items that have been entered into the collection but not yet in SP won't have an ID and this could be another possible reason why your code isn't working.

eka24
Level 10

Re: Remove collection item based on gallery check mark

All your codes seems in line. Put the same code on OnUncheck. I guess you did it only on oncheck.
Highlighted
ryanb1
Level: Powered On

Re: Remove collection item based on gallery check mark

Thanks for the idea. For OnCheck I've now changed it to

Collect(CheckedItems,ThisItem)

 and OnUnCheck

Remove(CheckedItems,ThisItem)

It seems too simple but it works. Am I missing anything? 

eka24
Level 10

Re: Remove collection item based on gallery check mark

I suggested you put the same code OnUncheck and Oncheck as in the article you cited.
If(!IsBlank(LookUp(CheckedItems,Id = ThisItem.Id)),Remove(CheckedItems,ThisItem),Collect(CheckedItems,ThisItem))
eka24
Level 10

Re: Remove collection item based on gallery check mark

If it's resolved kindly Mark as a Solution.
ryanb1
Level: Powered On

Re: Remove collection item based on gallery check mark

Thanks for the suggestion but it didn't work. 

 

In the end I went for the solution described in this video where the appropriate fields are saved into a collection in the OnCheck property; then onselect for a button saves that collection to the datasource. OnUncheck removes the item by finding the first item that matches the filter.

View solution in original post

Helpful resources

Announcements
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (4,728)