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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (38,452)