Help

Automation script not updating linked record field

Topic Labels: Automations
Solved
Jump to Solution
3743 7
cancel
Showing results for 
Search instead for 
Did you mean: 
Michael_Benson
6 - Interface Innovator
6 - Interface Innovator

Hi there,

I have built an automation that will:

Step 1: Trigger when a record is created in Table A
Step 2: Find matching records based on a condition in Table B
Step 3: Update a linked field on all matching records from Step 2 with the ID of the new record from Step 1

For Step 3 I have written a script as I understand the “update record” feature can’t handle multiple records.

The script isn’t producing any errors however it isn’t working. It should update the field “Applicant Record” with the record ID from Table A - at the moment nothing is being added.

Would you be able to help check if I’ve made a mistake with my code?

Screenshot 2022-02-03 150158

Cheers!

1 Solution

Accepted Solutions

Hi @Michael_Benson you can use console.log so something like:

for (let record of enquirerRecords) {
   console.log(record}
}

See Solution in Thread

7 Replies 7

In your for loop, start by logging record. This might not be in the right format for the updateRecordAsync method. You can pass in a record id or a record from a query result, but I wonder if the list of records is giving you something completely different.

Thanks Jonathan - this is a newbie question, but how should I go about logging record? Should I be using the output object? Any help getting started here would be great!

Hi,
i think you can achieve your goal without script, via usual ‘Update record’ step
you can’t update multiple records, but you can update a single record that triggered automation (step 1), by putting a result of step 2 into it’s linked field.

but anyway, you might want to debug your script and understand why it isn’t working. comment your ‘await enquirerTable…’ command and put console.log(record) and/or console.log(applicantID) near it to check what’s happening

Hi @Michael_Benson you can use console.log so something like:

for (let record of enquirerRecords) {
   console.log(record}
}
Michael_Benson
6 - Interface Innovator
6 - Interface Innovator

Thanks guys. I think I’ve worked out the problem.

It seems the script is triggering too quickly. It is set to trigger when a new record is created, but sometimes a user might create a record and then spent 5-10 seconds filling out the fields that this script would use to find a match in Table B.

The script is triggering before those fields are filled out, therefore it isn’t finding any matches and is failing.

What is the best practice here to setup a trigger that fires when a) a new record is created, and b) a specific field on that new record is filled out?

Yes, the record is created as soon as the empty row appears (or very shortly afterwards). A couple of ways around this:

  • Always create the record with an Airtable form. This ensures that all of the relevant fields are populated on creation.
  • I sometimes define a formula field that works out if key fields have been populated. It returns zero if they haven’t and 1 if they have. You can then trigger your automation on “when record meets conditions” - namely that this field is 1. You could make the conditions explicit on the key fields, but I find the formula method a bit easier to manage if there are lots of mandatory fields.

If the user is completing the data entry in the Airtable, consider running the script from a button instead of the automation. This way the user doing the data entry can click the button as soon as the data entry is done.

Using Scripting app instead of an automation will

  • free up an automation slot
  • not use up automation runs
  • give the user control over exactly when the script runs with regard to data entry being complete
  • allow the script to provide feedback if there is an issue with the inputs
  • allow you to use script settings so that the script will still work if table or field names change