cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AnthonyPhan
Kudo Kingpin
Kudo Kingpin

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
Jeff_Thorpe
Super User
Super User

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.

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
Community Champion
Community Champion

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

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.

@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
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

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Top Kudoed Authors
Users online (42,838)