cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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

CountRows(Gallery1.AllItems)

of all items to return a result

 

Edit:

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

6 REPLIES 6
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.

 

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. 

Super User
Super User

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})
 )

 

 

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

 

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?

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

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (13,270)