The reason you are putting this into an Automation is because you are wanting this linking of a record to a sibling record in another table to happen automatically for each record, as the record is created/updated, right?
Automations are designed with the intention of acting on one record at a time, and so I’m going to assume that what I stated above is the case.
If that is the case, then you do not need to fetch all the records from your main table and loop through them, establishing the link for each one — they have already been linked, for the most part, so you are redoing a bunch of work that has already been done.
You are wanting, here in this Automation, to link just the record that triggered the Automation. And you already have access to that record, because it was passed into the Automation actions. You can access it in your script by passing it through the
input variable, and retrieving it from
input.config(). Then you can directly update just the one record, without having to loop through all the records in your main table.
I’m on my phone right now so I can’t provide much in the way of further explanation, but I’ll try to hop on my computer later tonight and expand more on this.