cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
tianaranjo
Level 8

Add ID to collection

 

Looking for help with creation of a collection utilized only within the app, no external datasource.  I want to include an ID column in the collection with a count of each item.  The trick is that the data being collected is from a ComboBox so all standard ways of adding the id are not working, i.e. Collect(colThisItem, {id: CountRows(colThisItem) + 1, Result: ComboBox.Selected}) (@ericonline - thanks for the formula).  

 

The ComboBox1 items are populated from another collection:

  • Items - colComboBoxChoices
  • OnChange - Collection(colSelectedItems, ComboBox.Selected)

This works fine for collecting.  However, if I add the CountRows within the OnChange formula , it does not work as intended.  Again, I believe it has to do with the results for the colSelectedItems coming from a ComboBox - just not sure how to resolve.

Help would be appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Microsoft dinusc
Microsoft

Re: Add ID to collection

Thank you for clarification. Pease try setting this to OnChange:

Clear(colThisItem);ForAll(ComboBox1.SelectedItems, Collect(colThisItem, {ID: CountRows(colThisItem)+1, Result:Last(FirstN(ComboBox1.SelectedItems, CountRows(colThisItem)+1)).Value}))

If you're experimenting with a new ComboBox control with a default data set then change the last "Value" to "Value1".

Let me know if you have any questions in regards to the proposed formula.

View solution in original post

5 REPLIES 5
Microsoft dinusc
Microsoft

Re: Add ID to collection

Hello tianaranjo,

 

Please note that "OnChange" on the ComboBox is actually fired every time the selection is changed internally or by user interaction. As a result, it fires far more often that expected. Please consider one of the following workarounds:

1. Replace ComboBox control with a DropDown, which fires the "OnChange" only on user interaction (on closing the flyout). DropDown does not support multiple selections but since you're using ComboBox.Selected (and not ComboBox.SelectedItems), I assume you do not need that.

2. Store the previously selected value and perform the increment (+1) only in case the currently selected value is different from the previously selected value (in which case the previous value is also updated). This way, the "OnChange" event will fire only once.

Hope this helps.

tianaranjo
Level 8

Re: Add ID to collection

@dinusc  Thanks for your reply.  Thing is, I do need the user to be able to select multiple items if they choose; that need eliminated ability to utilize drop down.  

 

Any other thoughts that would allow user to select one or more?

 

Thanks again!

Microsoft dinusc
Microsoft

Re: Add ID to collection

Just so I understand the intended behavior, let's say I have a ComboBox with 10 items. If I want to select 3 of them (1, 4 and 6 for example), do you want to have a collection with 3 rows as following?

{id:1, Result:["Item1"]},{id:2, Result:["Item1,"Item4""]},{id:3, Result:["Item1","Item4","Item6]}

 

If you need just one row (as the last one) in your collection then you will need to have a button that the user clicks when he/she is done selecting items.

 

In your formula, you use ComboBox.Selected which should not be used in multi-select mode.

tianaranjo
Level 8

Re: Add ID to collection

So, if you have 10 items and select three used in example below, I would like them to appear in collection as:

ID  Result

1    Item1

2    Item4

3    Item6

 

A user might pick one of the selected or all 10. Did this help?

 

If so, how do I:

  1. Create a collection so the results are as shown above
  2. What do I do in place of ComboBox.Selected

Thanks!  I've been banging my head against my desk for days on this one.

Microsoft dinusc
Microsoft

Re: Add ID to collection

Thank you for clarification. Pease try setting this to OnChange:

Clear(colThisItem);ForAll(ComboBox1.SelectedItems, Collect(colThisItem, {ID: CountRows(colThisItem)+1, Result:Last(FirstN(ComboBox1.SelectedItems, CountRows(colThisItem)+1)).Value}))

If you're experimenting with a new ComboBox control with a default data set then change the last "Value" to "Value1".

Let me know if you have any questions in regards to the proposed formula.

View solution in original post

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 (Last 30 Days)
Users online (4,688)