cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Community Champion
Community Champion

Add and remove items from collection

This is a basic "How to" that I just need to get right. Please weigh in with your best practices. 

 

Scenario: 

  • Users must complete any 2 of 10 potential items
  • The items are controlled by a dropdown
  • The drop down has 3 options (-, Demonstrated Proficiency, and Exceptions Taken)
  • "-" is the default

Workflow:

  • OnVisible for the screen, a collection is created with empty values:
    • ClearCollect(comps,
          {comp_num: " ", 
           selected_competency: " ", 
           value: " "})
  • OnSelect property for a given dropdown, item is added to the collection
    • Patch(colComps,
              Defaults(comps),
                  {comp_num: "1", 
                   selected_competency: label.Text, 
                   value: "Demonstrates Proficiency"})    
          
  • To ensure user selects at least 2 of the 10 items to complete: DisplayMode property of the "Submit" button: 
    • If(
          CountRows(comps) < 2, 
              DisplayMode.Disabled, Edit)

 

THE PROBLEM: 

  • When a user changes their mind and goes from "Demonstrates Proficiency" to "Exceptions Taken" an additional record is added to the collection. 
  • When a user changes their mind and goes from either "Demonstrates Proficiency" or "Exceptions Taken" to the default "-", the record is not removed from the collection.
  • How do I add and remove items from a collection in this scenario?  
1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

I don't have it in front of me but I think you can use OnChange. Then have an If statement. Check to see what was there and then take action from there. 

Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training

View solution in original post

3 REPLIES 3
Super User
Super User

I don't have it in front of me but I think you can use OnChange. Then have an If statement. Check to see what was there and then take action from there. 

Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training

View solution in original post

Moving the formula to OnChange did indeed work, thank you @Shanescows. For anyone else reading this, beware, you can get tripped up if you don't consider this:

  • When you are in editor-mode (not preview), and you're using OnChange, you have to make your selection and then click off of the control to have the OnChange take effect.

This had me wrapped around the wheel for a good hour cursing at the PowerApps gods. Just remember, its not really OnChange... its OnChange-then-click-elsewhere-to-take-effect.

 

Hope this helps

Moving the formula to OnChange did indeed work, thank you @Shanescows. For anyone else reading this, beware, you can get tripped up if you don't consider this:

  • When you are in editor-mode (not preview), and you're using OnChange, you have to make your selection and then click off of the control to have the OnChange take effect.

This had me wrapped around the wheel for a good hour cursing at the PowerApps gods. Just remember, its not really OnChange... its OnChange-then-click-elsewhere-to-take-effect.

 

Hope this helps

Helpful resources

Announcements
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (5,682)