Help

Re: Automated script gives vague error

Solved
Jump to Solution
1305 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Marlene_Kingsto
4 - Data Explorer
4 - Data Explorer

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)

image

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.
image

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?

12 Replies 12

Do you know why it works without await but not with it? If it works without await then the data/data structure can’t be the issue. I’m pretty sure it’s an airtable quirk because I’ve done this in other javascript applications.

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.

Ok, I can’t believe I forgot to mark my function in my loop as async. You’re right about updating them in bulk, but I have over 50 records that need to update so I still have to update within the loop, but I currently have it set up to update the max allowed records at a time on each iteration. Thank you.

I might also mention that I needed to change the way I looped since the await doesn’t run in a forEach. I changed it to a for of loop and wrapped it in an async function. Now everything is working as expected.