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

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 II
Helper II

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 II
Helper II

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.

Helpful resources

Top Solution Authors
Top Kudoed Authors
Users online (3,211)