- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 16, 2021 04:07 PM
I am attempting to set up an automation and have a script update a linked field in a table. When testing my script the output gives me this error. “Your script has a syntax error” (adding this for search engines cause I could not find this on google at all)
The bit of code that makes this error happen is this (it has no syntax highlighted saying it’s an error)
await customersTable.updateRecordAsync(depo, {
'Dams': dogs
})
depo
is from here
let depo = depositors.getRecord(depositors.recordIds[index])
depo
looks like this when logged: {id: "rec1231412312", name: "Some name"}
dogs
is an array of objects (“dog” records) like this.
I’m not sure where to go from here cause this error leads me nowhere. I have tried just passing an array of IDs. I’ve tried passing an array of objects with just the IDs and not the name. Nothing has worked so far. Is anyone able to tell me what I’m doing wrong?
Solved! Go to Solution.
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 18, 2021 09:28 AM
You can use await inside a loop, and inside an anonymous function. You just have to declare the function as an async function.
puppyAvailability.forEach(async (dogs, index) => {
On the other hand, even though this is possible to use await inside the loop, it is better to update the records in bulk after the loop.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 16, 2021 04:35 PM
Hi @Marlene_Kingston, and welcome to the community!
What is the value of depo
when the updateRecordAsync() executes?
It appears you are actually trying to update multiple records. If so, you need to review the sample for updateRecordsAsync() -
// Update two records in the Big Tickets table
let table = base.getTable("Big Tickets");
let query = await table.selectRecordsAsync();
let records = query.records;
await table.updateRecordsAsync([
{
id: records[0].id,
fields: {
"Name": "Update one",
},
},
{
id: records[1].id,
fields: {
"Name": "Update two",
},
},
]);
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 17, 2021 12:09 AM
Hi @Marlene_Kingston - if depo
is a single record and updateRecord
singular is what you are after, then I think it might be dogs
array that is at fault here. I’m assuming that ‘Dams’ is a linked field - if so the write format for a linked field is:
So, your dogs
array needs to be:
[{id: 'recabc123456789'}, {id: 'recxyz43434343'}]
so exclude the name
attribute
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 17, 2021 07:33 AM
‘Dams’ is a linked and I am attempting to update only a single record. I have tried the format you suggested but no dice.
It still gives the same error.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 17, 2021 07:37 AM
depo
is a record from the customers table obtained from the line I mentioned above depositors.getRecord(depositors.recordIds[index])
so it looks something like this when I log it:
{id: "rec1231412312", name: "Some name"}
I am attempting to update a linked field in a single record with the dog IDs. I tried the suggestion JonathanBowen gave in his answer, but it doesn’t seem to work. Or maybe that fixed an issue but there is still another.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 17, 2021 08:49 AM
Okay - if you’re going to do this (above, a single record update), the first issue you need to resolve is that “depo” must be a record ID, not an object as it appears is the case.
If depo is actually an object as you describe, i.e., …
{id: “rec1231412312”, name: “Some name”}
… then you need to specify depo.id
to successfully call the Airtable API.
I would test this with dogs
hardcoded as “Fido” just to rule out any other issues.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 17, 2021 09:59 AM
It appears that you can’t update records within a loop. I didn’t give the full context of the code because I didn’t think it was necessary, but apparently it was.
So I added a testing field as a single line text field just to be sure it wasn’t anything with the field type and this still didn’t work.
puppyAvailability.forEach((dogs, index) => {
let depo = depositors.getRecord(depositors.recordIds[index])
await customersTable.updateRecordAsync(depo.id, {
'testing': 'Fido'
})
}
})
So I pulled the record update function outside of the loop and hardcoded values with the original fields and it worked just fine. (After I used depo.id
). So I’m assuming airtable doesn’t like to update within a loop?
let depo = depositors.getRecord(depositors.recordIds[0])
await customersTable.updateRecordAsync(depo.id, {
'Dams': puppyAvailability[0]
})
I was hoping to update within the loop, but it looks like I’ll have to restructure the data to work with the multiple record update.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 17, 2021 10:54 AM
Um, no. We perform iterative updates all the time. In fact, when you rebuild your code, factor in the use of updateRecordsAsync() for fifty at a time unless you want this to take forever. :winking_face:
I think you have a map issue in your code. Something is not mapping properly from puppyAvailability to depositors and index.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 18, 2021 07:59 AM
I got it figured out. It doesn’t let you await
in a loop. Not sure why. I just took out await
and it worked.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 18, 2021 08:03 AM
I’ve heard this many times just before a developer says - hey, why would some records not get updated from this looping process. :winking_face:
