Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

Looping through all items in a gallery

Was there a recent change regarding gallery functionality?

I'm trying to loop through all values in a gallery (Collection as source) and patch any changes to the collection itself.


I'm fairly certain the following was working


ForAll(Gallery1.AllItems,Patch(workorderItems,First(Filter(workorderItems,itemNum = inputNum.Text)),{itemDesc:inputDesc.Text}))



But now I can't even get


of all items to return a result



I've changed absolutely nothing butCountRows(Gallery1.AllItems) is now returning a result.

Super User
Super User

If you can think through a way to have your ForAll to only Patch the ones that were changed that would work better for you. It may just be too much because with that you are trying to Patch stuff that doesn't neccessarily need to be. 


There are several ways you can do that but one is to compare what is in the text input to the original (ThisItem.Column) and if they don't match then do the Patch and if they do then skip it. 

Currently I'm only dealing with a collection that's under 10 items long, with 3 values each, so I didn't bother with any optimization, but thank you for the suggestion.


My current problem is that the ForAll(Gallery1.AllItems,...) from my original post does nothing even when the collection is only 1-2 items in length.




I've done some testing with Concat(Gallery1.AllItems,inputDesc.Text), and it's output is equivalent to the values from the collection, not the "dirty" textboxes themselves. 

Super User
Super User

What is the "First" portion of your code for?


When I use Patch for my gallery I either do:


  LookUp(SpList, Title=Title1.Text),







was using first to pull the first record in the event that something caused the field I was matching on to return multiple records.

Though seeing yours I should, and will replace it with lookup.

However, as per my previous edit, it looks like the textbox.value isn't returning the dirty value of the text box, but the underlying collection elements value.


Switching to lookup :

	LookUp(workorderItems,itemNum = inputNum.Text),

yields no apparant change, however if I change the itemDesc assignment to {itemDesc:"."&inputDesc.text}, I can confirm that it is updating the collection, but using the current collection values instead of the textbox values.



Further testing before bed is yielding some more oddities.




















In the above picture all values in the gallery are clean (They are equivalent to the value in the collection); however if I create a label with the formula Concat(Gallery1.AllItems,inputDesc.Text) I don't get the expected "ABC" string, but if I do a CountRows it (correctly) returns 4.




 I can replicate this consistently if I patch the collection records, and immediately insert a new item following it:


	ThisItem,	{itemNum:Value(inputNum.Text),itemDesc:inputDesc.Text,itemComment:inputComment.Text}


Note: removing the Collect formula however seems to cause it to work as expected, and consistently return the expected string.



Additionally I am no longer able to use an in-gallery item with the OnSelect formula :


to delete items consistenly.


What it seems to be doing instead is deleting the 1st item sometimes, but only if executed within the 1st record.Delete1.png


Following which it won't delete the new 1st record until a chance has explicitly been made to that item, or a new item added to the collection.



I have only got one cup of coffee in me so far so I may be 


It looks like everything you have is working with the collection and you need one final step that takes the items in your collection and modifies/adds them to your data source. ~ Unless you have that part too and just didn't include that in your notes. 


Do you have that last step?

Adding the collection to my data source at submission works fine; its updating/removing items from/manipulating the collection from the gallery that isn't working.

Helpful resources

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

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!


Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (18,700)