cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User
Super User

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
Highlighted
Super User
Super User

Re: Add and remove items from collection

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
Highlighted
Super User
Super User

Re: Add and remove items from collection

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

Highlighted
Super User
Super User

Re: Add and remove items from collection

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

Highlighted
Super User
Super User

Re: Add and remove items from collection

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
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors
Users online (6,458)