Hey guys,
I'm having a hard time with a ForAll and Collect formula.
The selections that I have are:
combobox1 = text1, text2
combobox2 = value1
Value email1 is linked to text1 and email2 is linked to text2.
Based on selections and dependencies in combo boxes, the final result should be like this:
column1 | column2 | column3 |
text1 | email1 | value1 |
text2 | email2 | value1 |
Instead it generates this:
column1 | column2 | column3 |
text1 | email1 | value1 |
text1 | email2 | value1 |
text2 | email1 | value1 |
text2 | email2 | value1 |
In this case the email1 should not get text2 and email2 should not get text1 information in column1.
If I add value2 besides value1 to column 3, it will generate another set of 4 rows, but with the value2 on column3.
The formula looks like this:
ForAll(combobox1.SelectedItems As a1,ForAll(combobox2.SelectedItems As a2,ForAll(combobox3.SelectedItems As a3,Collect(collection,{column1:a1.Title,column2:a2.Email,column3:a3.Title}))))
If you have any thoughts, it would be much appreciated. Thank you!
The biggest issue is that your formula has the ForAll backward. You are trying to use it like a ForLoop in some development language - which PowerApps is not. ForAll is a function that returns a table of records based on your iteration table and record schema.
It is more efficient to use the function as intended and will provide better performance.
And in your case, you need to realize that each ForAll is creating a table. AND, each ForAll takes a parameter (the second) to specify the record schema of the table returned from the ForAll...so, since you are not specifying it, it is creating (based on the flow of your formula) a Table with a column that has a table that has a column that has a table....so, you are getting a lot of table-in-table results and your results will be as you are seeing.
Can you describe a little more on the Items properties of Combobox 1, 2 and 3? What you are trying to achieve is usually handled better within the Items property. Also, if you have a DefaultSelectedItems property set on any of them, what are those.
I ask more because you mentioned combobox 1 and 2 in your post, but your formula references combobox3 and the relationship did not seem apparent.
Yes, I am very aware of that. But I couldn't find another solution at the time.
The Items Properties of Combo Boxes are Share Point lists because I'm trying to avoid to hardcode them in the app.
Basically I'm trying to create an access request app where the user can select the various combinations of options and then those selections are recorded to a Share Point list from where they are processed by an Approval flow.
So let's say I want to request a regional access for a dashboard. I select the dashboard that I want access to (let's say dash1), I select Regional access, then on the next combo box I am presented with RegionA, RegionB, RegionC (each of them has different approvers). I pick RegionA and RegionC. Now, I want this information to be patched to a Sharepoint List like this:
dashboard | accesstype | accessname | approver |
dash1 | Regional | RegionA | email1 |
dash1 | Regional | RegionC | email2 |
Thank you!
I think you would understand better what I'm trying to do from the post were it was recommended to me to use ForAll.