Help

Airtable Script - "when a record matches conditions" -> How do I get the records that triggered the automation?

Topic Labels: Scripting extentions
6380 15
cancel
Showing results for 
Search instead for 
Did you mean: 
TFP
6 - Interface Innovator
6 - Interface Innovator

I configured an Airtable automation script to trigger when a record matches some conditions.

I had expected to somehow get an “input” containing the said records, but it feels like there isn’t such thing. My goal is to perform processing for the said records only.

image

I didn’t find anything in the API reference Airtable Scripting.

Is it possible? If not, what’s the recommended way to about that? I’m thinking about iterating over all elements and check if some field is empty and if so then perform some processing for that record.

Also, I read that only 15 records can be updated per second, how does this work? Is it handled by Airtable automatically or do I need to temporize the updates myself so that I don’t go over the limit?

15 Replies 15
Marko_Petrovic
7 - App Architect
7 - App Architect

If I understood you correctly, you can use input.config() to pull information from Trigger into the script.
You have setup windows to the left of scripting block where you can configure it and than use in your script. Here is example in a script I made some time ago where you can see how its done (there is a lot of unnecessary stuff in the script itself but it was one of the first I made so i was marking and checking each step :D)

InputLog

TFP
6 - Interface Innovator
6 - Interface Innovator

Thanks, I tried to use it but when I create an input variable, I’m not able to run the script anymore. :thinking:

The “Test” top-right button gets disabled and I don’t understand what I’m supposed to do.
Removing the input variable fixes it. This is confusing.

image

Marko_Petrovic
7 - App Architect
7 - App Architect

Hmm, did you try to re-test trigger step again after adding input.config? You need it to be success for script to be able to run, might be there was some issue there, at least judging buy the message you get
Maybe some of our fellow forum members with more experience at scripting could provide some additional insight.

Christoph_Molit
4 - Data Explorer
4 - Data Explorer

Did you solve it?
I have the same problem when i use input.config and it says:

(property) config: (options: {
title: string;
description?: string;
items?: ConfigItem;
}) => any
Expected 1 arguments, but got 0.(2554)
9(42, 1): An argument for ‘options’ was not provided.

I hope you can help me…

No, I did not. I did something different which doesn’t use inputs.

Is there a more computationally economical way to do this? I have an automation set up almost exactly the same way as you, but it takes 11s to update a single record, because every time it has to query the entire table (5600+ records) just to get the record that is already identified by the automation trigger, because AFAIK the only way to do this is with await selectRecordsAsync() and then await getRecord(), meaning even though the record should already be known because it tripped the trigger, I have to query ALL records and then essentially filter by the id from the trigger’s input.config()… this is extremely wasteful.

Is there no way to just getRecordbyID() from input.config()[‘record_id_from_trigger’]??

My ideal pseudo-code would be as simple as this, and MUCH faster:

let data = input.config();
let table = base.getTable('Table');
let record = await table.getRecordByID(data.id);
await table.updateRecordAsync(record, {'Field': 'Updated Value'});

or, even more ideal, the whole record object should already be captured by the automation, and accessible through input.config(), not just the id from input.config()so you could do:

let record = input.config().the_actual_record_object;
let table = base.getTable('Table');
await table.updateRecordAsync(record, {'Field': 'Updated Value'});
TFP
6 - Interface Innovator
6 - Interface Innovator

There is definitely a way to optimize this.

Using the same workflow, you could use filterByFormula to filter the records you want, and this would likely decrease your query time quite a lot, by ignoring all records that don’t match your criteria. (you could filter by ID, in your case)

Avana_Vana
6 - Interface Innovator
6 - Interface Innovator

I actually figured out you can just do: (if you set up a var called ‘id’ in your automation)

const data = input.config;
await table.updateRecordAsync(data.id, { 'Field': 'Updated Value' });

So I would recommend doing that :slightly_smiling_face: .

Ross_Patton
4 - Data Explorer
4 - Data Explorer

Same issue here as OP. Any attempt to add input variables that aren’t hard-coded break the script. Not trying to do anything complicated here, just want to be able to reference the id of the record in question instead of having to query the entire table like all the examples show. When I try to run the script, it says I must “test all input steps successfully” but doesn’t explain how to do this, or where, and it’s really not clear what the issue is

Anyway, I figured it out, so hopefully this post helps someone in the future. The UI here really needs work. Solution → You have to exit the code editor and run the event trigger step again before it will let you access any dynamic input variables. A better error message or simply allowing the user to run a test via the input vars panel would alleviate the confusion here

Oh my goodness, you figured it out. This error drove me crazy for months and the support team was useless to help me solve it. UX is shitty indeed. Glad you shared it!

Ates
5 - Automation Enthusiast
5 - Automation Enthusiast

there’s no way to add input. I still can not find how to pass inputs. All i am trying is when status changes to active, i want to send a webhook and pass some data of the updated record.

You’re actually right, we cannot define the value (record id) to be used by the script.

I recorded a video to explain the workflow a bit in-depth: Airtable Script - "when a record matches conditions" - How do I get the records that triggered ... -...

@Ross_Patton I think your answer is misleading, because @Ates and I assumed you found a way to set variables, but the only thing Airtable provides is a way to see what values are being used (at least when using a record id).

Hi,
you can input any data from records participated in previous steps. Also, you can use one script step to form and pass any value to another step
Annotation 2021-09-01 053417

in some table, i had to use script step to convert formula result, because otherways it refused to work properly in “Find records” filter. WIth script, it worked perfect.
Annotation 2021-09-01 053526

Other example, i used small table and it’s top record with Single select to add some interactive actions with current and other tables (update links, create reports), because “Button field” feature lacks some functionality, at least ability to show/hide buttons (that’s why variable called “button” despite it’s a ‘single select’ field):
Annotation 2021-09-01 052943

Interesting! I wasn’t aware we could provide values from one script to another within the same automation. I had looked for that feature but couldn’t find any official documentation about it, is it new? Would you have a link to the official doc?

I don’t think it solves the root issue at hand, because it doesn’t really make it any more straightforward to go through such an additional step, and I believe it also complicates things, but that’s still interesting to know, as a workaround. (I’m not sure to understand well how you use it to provide your own custom values, though)

I’m not sure about how long it exists here, I’m started to work with airtables and learn javascript in June.
When you change something about input or output data of some step, you have to re-test each step before.
Another case, one time, my new automation step ‘find records’ didn’t work. Actually, it worked, but didn’t find supposed records. That happened because I created it by copying existing one, but select other table&fields. Some filter step became ‘invalid’ several days ago because I had one field error in my base for a short time, but automation config didn’t show that error.
After some useless debug attempts, i just deleted it and created new one, and it worked.

It seems like I can’t understand what the problem with root issue. I just can show an example howTo, hope it will helps anyone reading this topic (sorry for some “ninja-code”, i’m dba, not a developer)

image

choose trigger, select fields:

128

use script step

image

Use desired field values:

45348

name these variables, so you can use them in script instead or getting record from query and get cellValues

image

you will see possible variables during script input

811

finally, define script output variable (or several variables):

image

Use it in next step:

Annotation 2021-09-01 152411

And that’s it: :grinning:

image