Feb 03, 2022 07:06 AM
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?
Cheers!
Solved! Go to Solution.
Feb 06, 2022 04:27 AM
Hi @Michael_Benson you can use console.log
so something like:
for (let record of enquirerRecords) {
console.log(record}
}
Feb 05, 2022 06:30 AM
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.
Feb 05, 2022 09:51 AM
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!
Feb 05, 2022 10:24 PM
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
Feb 06, 2022 04:27 AM
Hi @Michael_Benson you can use console.log
so something like:
for (let record of enquirerRecords) {
console.log(record}
}
Feb 06, 2022 05:01 AM
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?
Feb 06, 2022 12:57 PM
Yes, the record is created as soon as the empty row appears (or very shortly afterwards). A couple of ways around this:
Feb 06, 2022 05:18 PM
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