web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Collections within a F...
Power Apps
Unanswered

Collections within a ForAll not working

(0) ShareShare
ReportReport
Posted on by 22
These two collections are trying to build code that should be included in PowerApps but big surprise, there's no way to do it without CODE!!  The combobox cmbInteriorAreasOfConcern1 can "Alllow multiple selections" and this combo box is tied to a relational database which means that each selected item is a seperate row in a SQL table.  Therefore I need two seperate (patch and remove)commands to maintain this data in SQL.  One patch to remove the unselected items in the combo box and a second to insert newly selected items.  The code below is attempting to build two collections to store the table elements to allow a patch command to insert the new records and remove to delete the unselected elements.  The combo box selecions are the element named "field_value". 
Clear( cllctInsertIntAreaCo );
ForAll(
Filter( 'AWP1.picklist_intareaco', field_value in cmbInteriorAreasOfConcern1.SelectedItems.field_value , work_order_nbr = "0"
, cmbInteriorAreasOfConcern1.Selected.field_value = ThisRecord.field_value ) // As ins_IAC
, Collect( cllctInsertIntAreaCo
, {
t_id : ThisRecord.t_id // cmbInteriorAreasOfConcern1.SelectedItems.t_id // ins_IAC.t_id //
, work_order_nbr : varItem.work_order_nbr // ThisRecord.work_order_nbr // ins_IAC.work_order_nbr //
, picklist_nbr : ThisRecord.picklist_nbr // cmbInteriorAreasOfConcern1.SelectedItems.field_value // ins_IAC.picklist_nbr //
, field_value : ThisRecord.field_value // ins_IAC.field_value //
}
)
);
Clear( cllctRemoveIntAreaCo );
ForAll(
Filter( 'AWP1.picklist_intareaco', Not( field_value in cmbInteriorAreasOfConcern1.SelectedItems.field_value ), work_order_nbr = varItem.work_order_nbr ) As rmv_IAC
, Collect( cllctRemoveIntAreaCo
, {
work_order_nbr : rmv_IAC.work_order_nbr // varItem.work_order_nbr
, t_id : rmv_IAC.t_id //ThisRecord.t_id // varItem.t_id
, field_value : rmv_IAC.field_value //ThisRecord.field_value
, PLD_Nbr : rmv_IAC.PLD_Nbr // ThisRecord.PLD_Nbr
, picklist_nbr : rmv_IAC.picklist_nbr // ThisRecord.picklist_nbr // cmbInteriorAreasOfConcern1.SelectedItems.field_value //
}
)
);
These two collections should return all the elemets correctly.  The remove appears to work however the insert NEVER works.  Both TABLES that are passed to the ForAll are correctly returning the correct records and the correct values for all columns in the table "'AWP1.picklist_intareaco'" however every attempt to fill the collection FAILS.  I have tried a single insert without the ForAll and that doesn't work.  See the attachments that show the contents of both collections.
My gues is that the preview mode is broken and the preview is showing different data than the actual testing.  
Its just shocking to me, how many bugs in PowerApps like this one that I have run accross.  I do not know how anyone could build an app that someone would pay for with all the bugs that are in PowerApps.
cllcRemoveIntAreaCo_populated.png
cllctInsertIntAreaCo_Not_Correct.png
Categories:
  • WarrenBelz Profile Picture
    156,940 Most Valuable Professional on at
    You have used the As disambiguation operator in the second one - try it in the first - I have found it more reliable than ThisRecord
    Clear(cllctInsertIntAreaCo);
    ForAll(
       Filter( 
          'AWP1.picklist_intareaco' As ins_IAC,
          field_value in cmbInteriorAreasOfConcern1.SelectedItems.field_value, 
          work_order_nbr = "0", 
          cmbInteriorAreasOfConcern1.Selected.field_value = ins_IAC.field_value 
       ), 
       Collect( 
          cllctInsertIntAreaCo, 
          {
             t_id: ins_IAC.t_id, 
             work_order_nbr: varItem.work_order_nbr, 
             picklist_nbr: ins_IAC.picklist_nbr, 
             field_value: ins_IAC.field_value
          }
       )
    );
    Clear(cllctRemoveIntAreaCo);
    ForAll(
       Filter( 
          'AWP1.picklist_intareaco', 
          Not( 
             field_value in cmbInteriorAreasOfConcern1.SelectedItems.field_value 
          ), 
          work_order_nbr = varItem.work_order_nbr 
       ) As rmv_IAC, 
       Collect( 
          cllctRemoveIntAreaCo, 
          {
             work_order_nbr: rmv_IAC.work_order_nbr, 
             t_id: rmv_IAC.t_id, 
             field_value: rmv_IAC.field_value, 
             PLD_Nbr: rmv_IAC.PLD_Nbr, 
             picklist_nbr: rmv_IAC.picklist_nbr
          }
       )
    );
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    Buy me a coffee
  • ronaldwalcott Profile Picture
    3,914 Moderator on at
    What is the line containing this field_value in cmbInteriorAreasOfConcern1.SelectedItems.field_value meant to do?  Do you need to iterate through the selected values in the combobox?
  • CU14112135-0 Profile Picture
    22 on at
    Ronald,

    the iteration through the "field_value" is to collect each selection of the combobox.  The value in the table that I'm trying to collect is the "field_value" its the value being displayed in the combobox.
  • CU14112135-0 Profile Picture
    22 on at
    Warren,

    I have tried the "As" operator for both collections and I agree, this is the better approach, however in this case the cllctRemoveIntAreaCo still does not populate correctly.  I have even tried to collec the entire table without the ForAll and that does not work.  I seriously don't know how anyone could use this application for production, too many bugs. 
  • WarrenBelz Profile Picture
    156,940 Most Valuable Professional on at
     @CU14112135-0​​​​​​​
    It is a bit hard to comment much further as I do not use SQL with Power Apps, so am not aware of any "quirks" it may have. I also do not know what you mean by still does not populate correctly. If you are saying "not completely", there are two possible issues, one that your Collection record numbers is limited to your Data Row Limit and the second if the filter you are using is Delegable (which it appears to be). Other than that, the structure you are using seems valid.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 248 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 192 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard