cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
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
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

seadude
Level 10

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

seadude
Level 10

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
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 190 members 5,540 guests
Please welcome our newest community members: