cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AnthonyPhan
Level 8

Access gallery item in ForAll loop

Hi,

 

How can i access the value of a textbox that is nested within a gallery? What I am trying to achieve is loop though each item in the gallery and get the textbox1 value. to patch to a datasource.

 

I have tried the following. however the loops keeps accessing the first itean of the gallery instead of getting the row relevent to that part of the loop.

ForAll(Gallery1.AllItems, UpdateIf(Collection1, ID = ID, {TOOL: Value(TOOL_TI.Text)}))

 

NOTE: the following works if the collection is replaced with an SQL  database, however I require it to work fo a local collection.

ForAll(Gallery1.AllItems, 
       Patch(EmployeeWorkOrderAssignments,{ID:ID}, {TOOL: Value(TOOL_TI.Text)}
       )
)
5 REPLIES 5
Super User
Super User

Re: Access gallery item in ForAll loop

I think PowerApps is confused with the "ID = ID". It needs to know which one belongs to "Gallery1.AllItems" and which one belongs to "Collection1". Try this and see if it helps.

 

ForAll(Gallery1.AllItems, UpdateIf(Collection1, ID = Collection1[@ID], {TOOL: Value(TOOL_TI.Text)}))


--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.
AnthonyPhan
Level 8

Re: Access gallery item in ForAll loop

Hi @Jeff_Thorpe

 

I appreciate the response. I implemented your suggestion. For some reson it is now only referencing the last textbox in the gallery when looping.

Meneghino
Level 10

Re: Access gallery item in ForAll loop

Another way to dismbiguate is to rename the column in the gallery

ForAll(RenameColumns(Gallery1.AllItems, "ID", "GalleryId"), UpdateIf(Collection1, ID = GalleryId, {TOOL: Value(TOOL_TI.Text)}))

However, I think patching a table instead of one row at a time could be a better performing solution, something like this:

 

Patch(Collection1, ShowColumns(Gallery1.AllItems, "ID"), ShowColumns(AddColumns(Gallery1.AllItems, "TOOL", Value(TOOL_TI.Text)),"TOOL"))
Meneghino
Level 10

Re: Access gallery item in ForAll loop

Hi @Jeff_Thorpe, the diagnosis seems correct and the suggested direction is correct.

You must keep in mind however, that unless disambiguation is used, the dominant column is that of the inneremost expression i.e. the last named table.

Hence ID will mean ID of Collection1, so the solution you suggest should give the same result as ID=ID

I am not aware of a way to disambiguate a two part table name (i.e. Galler1.AllItems), as would be required, hence my suggestion to simply rename the column.

Super User
Super User

Re: Access gallery item in ForAll loop

@Meneghino, thanks for the insight. I think I have a better understanding now.

@AnthonyPhan, based on @Meneghino's feed back I believe this formula will work (at least it did in my test app). If @Meneghino solution doesn't workout for you, give this a try:

 

ForAll(
  AddColumns(Gallery1.AllItems, "tmpID", ID),
  UpdateIf(Collection1, tmpID = ID, {TOOL: Value(TOOL_TI.Text)})
)

It removes the disambiguation by putting the ID value in a temporary column and then the rest of the formula references the temporary column.



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 424 members 5,951 guests
Please welcome our newest community members: