Comparison of Two Separate Table Fields

I am trying to compare a value from one table against that value in a separate table to see if that value is on the one table. I did find code to get this to work and it seemed as though it was working, however I am finding that there are matching values in both tables that are not showing. It looks like the code is refusing to look at or compare values beyond the first 60. Any help is greatly appreciated.

Welcome to the community, @Vulcan_Village! :smiley: Could you share the code that you found? Without seeing that, it’s hard to know what might be causing the problem.

@Justin_Barrett S

Sure…Here it is:

let mainTable=base.getTable(“Survey Results”);

let mainTableRecords=await mainTable.selectRecordsAsync();

let lookupTable=base.getTable(“Deferral List”);

let lookupRangeRecords=await lookupTable.selectRecordsAsync();

for (let record of mainTableRecords.records) {

let lookupValue=record.getCellValue("CWID");

for (let rangeRecord of lookupRangeRecords.records) {

    if (rangeRecord.getCellValue("CWID")==lookupValue) {

        let returnValue=rangeRecord.getCellValue("CWID");

        lookupTable.updateRecordAsync(record, {

            "Completed": returnValue

            });

    }

}

}

I have also tried switcching the mainTable & lookupTable and it does not change the results.

The main problem that I see is that you’re missing “await” at the start of the line that’s updating the record in your lookup table. Without waiting for the update to finish, unknown issues can occur, and I’m guessing that’s the cause of your problems.

The downside of waiting for each update one at a time is that it can slow down the overall process. What’s recommended in a case like this is to build an array of all necessary updates, then call updateRecordsAsync to update your records in batches. Here’s the modified code to make that happen:

let mainTable=base.getTable(“Survey Results”);
let mainTableRecords=await mainTable.selectRecordsAsync();
let lookupTable=base.getTable(“Deferral List”);
let lookupRangeRecords=await lookupTable.selectRecordsAsync();

let updates = [];
for (let record of mainTableRecords.records) {
    let lookupValue=record.getCellValue("CWID");

    for (let rangeRecord of lookupRangeRecords.records) {
        if (rangeRecord.getCellValue("CWID")==lookupValue) {
            let returnValue=rangeRecord.getCellValue("CWID");
            updates.push({
                id: rangeRecord.id,
                fields: {
                    "Completed": returnValue
                }
            })
        }
    }
}

while (updates.length > 0) {
    await lookupTable.updateRecordsAsync(updates.slice(0, 50));
    updates = updates.slice(50);
}

@Justin_Barrett

I input that code and got the following error:

L: Can’t set cell values: No record with id recvYbr705d3OeqTv exists
at main on line 24

Sorry. My bad. I’ll fix the code above. Long story short, I used the wrong record ID in the update push. I used record.id, but it should have been rangeRecord.id