How To Load Records in Airtable Scripting App

Now if you are coming from the previous article, you already know about Scripting in Airtable. If not then I would like to recommend you read the first article and then continue. With that being said, Let's learn how you can Load records in airtable Scripting.

First, install the Scripting app which I already explained in the previous article. Then Copy and paste the below code into the Scripting app. Let's assume that we have a table called 'Teachers' that contains 'ID, Name, Email & Class' fields.

: Code :


let table = base.getTable('Teachers');
let query = await table.selectRecordsAsync();
output.table(query.records);

Understanding Code:

In the first line of code, we are declaring a variable that is 'table' and we are selecting the 'Teachers' table from my base. Then in the next line of code, we are executing the code and in the 'query' variable we are storing the results. Finally, we are printing results in the last line of code. There is another way you can print records like 'console.log(query.records)' but it's a bit complicated if you are new to programming. In 'output.table' format, it prints in a tabular format as you can see in the below Image.

Load Records in Airtable Scripting 1.jpg

Keywords Explanation

  • Base: Base provides entry points to get all records from any table in your base. After you type base in your script and put a dot after it, IntelliSense automatically suggests further options that you might want to select. This same is applicable to many different cases. Here we have 'getTable()' function in which you can pass the table's name which you want to select.
  • Await: Await is a keyword used in async functions such as 'selectRecordsAsync()'. It means that it will execute that line of code and once it receives all the data then and only then it can go further. I will explain the function in the next part of the article.

selectRecordsAsync() function

We have 2 functions to fetch data

  1. selectRecordAsync() - Fetch single record
  2. selectRecordsAsync() - Fetch multiple records

In the first function, you can pass the id as a parameter to fetch a single record. An interesting one is the second function where you can pass parameters to sort or you can choose to get only specific fields. Let me explain to you with an example.

: Code :


let query = await table.selectRecordsAsync({fields:['Name','Email'],sorts:[{field:'Class',direction:'desc'},]});

As you can see in the above example, you can pass which fields you want to select and on which field you want to sort with direction. If you want ascending order then you can omit the direction part. However, you can omit everything in parameters and still you will get records but it's for those who want specific results only.

So this is how you can get records from airtable base in your scripting app. Stay connected for more learning articles in this series.

Feel free to contact me for Airtable consulting services by CLICKING HERE.

monino solutions logo

COPYRIGHT © 2024 Monino Solutions.