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

Forall patch with lookup using As

Hi All
 
I am trying to use For All to loop through a collection I have tried using As and ThisRecord but no matter how i do it, it always updates the first record in the SQL Server table.
 
ForAll(
form_elements_collection As F,
If(
F.Action = "U",
Patch( '[dbo].[Field_element_data]',LookUp( '[dbo].[Field_element_data]' As C, C.Field_element_data_id = F[@Field_element_data_id] ),
{ Value_int: F.Value_int, Value_text: F.Value_text, Value_varchar: F.Value_varchar } ) ));
3 REPLIES 3
Super User
Super User

@jimmy_j 

You could try using RenameColumns on your collection, eg

 

ForAll(
RenameColumns(form_elements_collection,"Field_element_data_id", "FED_id") As F,
If(
F.Action = "U",
Patch( '[dbo].[Field_element_data]',LookUp( '[dbo].[Field_element_data]' As C, C.Field_element_data_id = F.FED_id ),
{ Value_int: F.Value_int, Value_text: F.Value_text, Value_varchar: F.Value_varchar } ) ));.

 

Sometimes this can work better than disambiguation.

 

Thank Eelman

 

It was worth a try!

 

I get error ribbon 

 

the specified record was not found. Server response: [dbo].[Field_element_data] failed: Invalid column name FED_id

 

 

It got the same thing when I renamed the column before the patch.

 

James

 

@jimmy_j 

Try removing the "... As C .." part and any references to it. It's not really needed and maybe causing the issue.

Helpful resources

Announcements
News & Announcements

Community Blog

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

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (8,718)