cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dungar
Helper I
Helper I

ForAll and UpdateIf alias/conditions

I've been reading about/trying this all day, and have just given up and need someone to help figure out what i'm doing wrong.  Using an Azure SQL database when talking about tables

 

The process-

 

Step 1: User selects records from recordTable into a collection (colRecords).  This works

Step 2: User fills out a form and submits it to summaryTable (basically sums up the records + some user input).  During this varSummaryID is populated and stored in a variable.  This also works.

Step 3: OnSuccess of the submitted form, I need to update the recordTable, which has a column called "SummaryID".  I have gotten this to either not work at all, or to update EVERY record in the table (100k ish records...well it tried to.  I caught it and killed it).

 

If this were SQL the final step would be

 

UPDATE recordTable

SET SummaryID = 'SummaryIDGoesHere'

WHERE recordTable.ID IN colRecords.ID

 

Obviously not a real statement, but just trying to get the idea across.

 

My attempt-

 

 

ForAll(
    colRecords,
    UpdateIf(
        recordTable,
        recordTable.ID = colRecords.ID,
        {Stuff to update}
    )
)

 

My issue is the condition logic- recordTable.ID = colRecords.ID

This variation will not work as you can't alias like this (recordTable.ID/colRecords.Id). 

Trying:

ID = ThisRecord.ID:  is what led to the "update everything" scenario, so i assume that's just it saying ThisRecord.ID = ThisRecord.ID

 

I've also messed with patching and lookups, but 90% of the questions on this relate to other issues. My problem here is that i'm taking the starting table, getting ID's from it, then trying to update that table for every ID selected, and yet I can't seem to get it to reference the right thing.

 

1 ACCEPTED SOLUTION

Accepted Solutions
dungar
Helper I
Helper I

Finally found a video that helped.  Final code-

 

ForAll(
    RenameColumns(colRecords,"recordID","TestID"),
    UpdateIf(
        'recordTable',
        'recordTable'[@recordID] = TestID ,
        {SummaryID:varSummaryID}
    )
)

 

As i suspected it was just an aliasing issue, and i'd totally forgotten about rename columns.

 

It drives me crazy how many little edge cases like this exist, where the product is ALMOST there, but I wind up stuck replicating basic functionality, and you wind up wading into syntax/expectation hell.

View solution in original post

1 REPLY 1
dungar
Helper I
Helper I

Finally found a video that helped.  Final code-

 

ForAll(
    RenameColumns(colRecords,"recordID","TestID"),
    UpdateIf(
        'recordTable',
        'recordTable'[@recordID] = TestID ,
        {SummaryID:varSummaryID}
    )
)

 

As i suspected it was just an aliasing issue, and i'd totally forgotten about rename columns.

 

It drives me crazy how many little edge cases like this exist, where the product is ALMOST there, but I wind up stuck replicating basic functionality, and you wind up wading into syntax/expectation hell.

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (1,456)