I have an app with various medical questions that I want to flag and collect a condition everytime the user selects "Yes". Here is an example of my code behind a toggle button: If(ynSmoker.Value,Set(ReviewFlag,true);Collect(ReviewItems,"Smoker"),false)
So my question would be, what if that user selects Yes, but then reverts back to No? I need to Remove that item from the collection. Would it be as simple as "Remove(ReviewItems,"Smoker")? I dont think it would be that easy I am guessing
Thanks,
Brad
Solved! Go to Solution.
Hello @guyinazo,
Here is the method I use to remove items from a collection. Hope this helps.
Collect( <collection_name>, {<column_name_1>: ThisItem.<column_name_1>, <column_name_2>: ThisItem.<column_name_2>} )
Remove( <collection_name>, First( Filter( <collection_name>, <column_name_1>=ThisItem.<column_name_2>) ), All)
Hope this helps your scenario.
Hi Brad,
You're right, it's not that simple! The Remove function works well against connected data sources, but it doesn't work against local collections. I think this is a bug in PowerApps.
If you have a unique id that identifies the record that you want to remove from the local collection, a more reliable way is to call the RemoveIf function.
Now I am trying to think logically how to do this. This questionnaire has around 50 of these medical conditions and if any of them are selected to "Yes", the app needs to capture that and I was thinking a Collection would work just fine (selecting Yes also trips a flag too but that is easy to handle). As I was working on this, I was thinking if the user selected the wrong toggle or said yes, then reverted back to No, how it would impact that collection. Perhaps I could do a massive IF statment on the Submit button? Also, I did see that topic that you referred to and I need to revisit it to see if I missed something.
Thanks
I think the approach of adding your logic to your Submit button might be best. That way, you don't need to worry about the possibility of a user toggling an answer from 'yes' back to 'no'.
Hello @guyinazo,
Here is the method I use to remove items from a collection. Hope this helps.
Collect( <collection_name>, {<column_name_1>: ThisItem.<column_name_1>, <column_name_2>: ThisItem.<column_name_2>} )
Remove( <collection_name>, First( Filter( <collection_name>, <column_name_1>=ThisItem.<column_name_2>) ), All)
Hope this helps your scenario.
Thanks @ericonlinefor this. I will try it, and also accepted as a solution for now. But yes, it is a bit quirky but dont see why it wouldnt work.
Brad
Cool. The "First(..", "Filter(...", and "All" will likely get you what you need.
So I am hoping something like this: If(ynSmoker.Value,Collect(ReviewItems,"Smoker"),Remove(ReviewItems,First(Filter(ReviewItems,Value="Smoker")))) <--This is in the OnSelect of the toggle
The only thing I was unsure of is the column name because there is only one column in this collection and it is not specified so looking at the example here: https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/create-update-collection it is Value.
I think you'll need to look closer at your Collect syntax. The curly braces and such.
I believe its Collect(<collection_name>, {<collection_column_name>:<value>})
And don't forget the "All". That parses the entire collection and removes all instances of the item. If for some reason the User recorded the same value twice, this would get both of them.
Stay up tp date on the latest blogs and activities in the community News & Announcements.
Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST
Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.
User | Count |
---|---|
207 | |
188 | |
80 | |
50 | |
38 |
User | Count |
---|---|
305 | |
252 | |
121 | |
73 | |
55 |