cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ericonline
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
Shanescows
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
Shanescows
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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

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