Help

Need Help with Script

Topic Labels: Extensions Sync
Solved
Jump to Solution
1188 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Aaron6
4 - Data Explorer
4 - Data Explorer

I have a script that has been working for over a year, but now will not update records.  I sync a table from another base to a second tab in main base.  I then use the following script I was given over a year ago (can't remember where I got it).  It has worked great to look at the synced tab to see a unique ID (emp #) and then pull that onto the main table and pull multiple records from the syned tab.  

Now when I run it the script runs super fast and doesn't update anything even though I have matching Unique IDs.

Here is the script I am using:


//Substitute "Orders" for table name which contains values
//on which you want to run the vlookup
let mainTable = base.getTable("Covid LOA");
let mainTableRecords = await mainTable.selectRecordsAsync({fields:["emp"]});

//Substitute "Product" for table which contains range to search in
let lookupTable = base.getTable("Proof");
let lookupRangeRecords = await lookupTable.selectRecordsAsync({fields:["Emp"]});

//Replace "Item.barcode" with column name which has the values you want to look up 
for (let record of mainTableRecords.records) {  
     let lookupValue = record.getCellValue("emp");

    //Replace "Barcode" with column name which is the range to search in
    for (let rangeRecord of lookupRangeRecords.records) {
        if (rangeRecord.getCellValue("Emp") === lookupValue) {
            let linkID = rangeRecord.id;
     
            //Replace "Product" with column name from mainTable which should contain the link
            await mainTable.updateRecordAsync(record, {
                "COVID FMLA Proof": [{id: linkID}]
            });
       }
    }
}
1 Solution

Accepted Solutions
kuovonne
18 - Pluto
18 - Pluto

When a script that has been working stops working, the first thing I look at is any schema changes that may have happened. Seemingly minor changes to field types can have big impacts to scripts. I’m guessing that you are not seeing any record updates because the script is not finding any matches, possibly due to the field types of the {emp} and {Emp} fields.

By the way, this particular script looks like it is a rather inefficient script. That may not be a problem as you are probably running it in scripting extension and not as an automation.

See Solution in Thread

3 Replies 3
kuovonne
18 - Pluto
18 - Pluto

When a script that has been working stops working, the first thing I look at is any schema changes that may have happened. Seemingly minor changes to field types can have big impacts to scripts. I’m guessing that you are not seeing any record updates because the script is not finding any matches, possibly due to the field types of the {emp} and {Emp} fields.

By the way, this particular script looks like it is a rather inefficient script. That may not be a problem as you are probably running it in scripting extension and not as an automation.

I'll take a look at field types.  

As for how I am running it, yes I am running it through Extensions as I don't know how to run as Automation within Airtable.  Any help guides or videos to help learn this?

Thanks @kuovonne !

The field type did the trick!  Not sure how it changed to a Number field or if it was always set that way.  I changed to a text field and worked!