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 / Looping through all it...
Power Apps
Unanswered

Looping through all items in a gallery

(0) ShareShare
ReportReport
Posted on by 24

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

CountRows(Gallery1.AllItems)

of all items to return a result

 

Edit:

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

Categories:
  • rebeccas Profile Picture
    2,591 on at

    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. 

  • JNicholl Profile Picture
    24 on at

    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.

     

    edit:

     

    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. 

  • rebeccas Profile Picture
    2,591 on at

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

     

    When I use Patch for my gallery I either do:

     

    ForAll(Gallery1.AllItems,
     Patch(SPList,
      LookUp(SpList, Title=Title1.Text),
      {Column1:TextInput.Text})
     )

     

    OR

     

    ForAll(Gallery1.AllItems,
     Patch(SPList,
      {ID:ID},
      {Column1:TextInput.Text})
     )

     

     

  • JNicholl Profile Picture
    24 on at

    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.


    Edit:

    Switching to lookup :

    ForAll(Gallery1.AllItems,
    	Patch(workorderItems,
    	LookUp(workorderItems,itemNum = inputNum.Text),
    	{itemDesc:inputDesc.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.

     

    Collection.png

    Gallery.png

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    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.

     

    Labels.png

     

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

     

    Patch(workorderItems,
    	ThisItem,	{itemNum:Value(inputNum.Text),itemDesc:inputDesc.Text,itemComment:inputComment.Text}
    );
    Collect(workorderItems,
    	{itemNum:Text(CountRows(workorderItems)+1),itemDesc:"temp",itemComment:""}
    );

     

    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 :

    Remove(workorderItems,ThisItem)

    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.

    Delete2.png

     

  • rebeccas Profile Picture
    2,591 on at

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

     

    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?

  • JNicholl Profile Picture
    24 on at
    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.

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 236 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 207 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 169

Last 30 days Overall leaderboard