How To Insert records through Airtable Scripting

In this article, I am explaining to you how to Insert records through Airtable Scripting. If you have read previous articles then you already know how to select records, Now let's learn how you can insert records in this article.

First, install the Scripting app which I already explained in the previous article. Then Copy and paste the below code into the Scripting app. Also, Let's assume you at least have one field called 'Name' in your table in order for the below code to work.

: Code :


let table = base.getTable('Teachers');
let recordIds = await table.createRecordsAsync([{ fields: { 'Name': 'Alice', },},{fields:{ 'Name': 'Bob',},},{ fields: {},},]);

Understanding Code:

So in this code first we are configuring a table in which we will insert the records. Then we are using a function to create the records. We have two functions that we can use to create records as follow.

  1. createRecordAsync()
  2. createRecordsAsync()

The first is used to create a single record and the second is for multiple records. I have given an example of the second one. However, it's simple to use the first function where just pass a single record in the function as a parameter and will create a single record.

Here in this function as you can see, we are inserting records and their array of objects. It requires a specific format as shown in the code. But if you notice, the Last record is not having any values in it. This record creates an EMPTY record in a table where all the values in cells will be EMPTY.

You can go through a loop and create as many records as you want, I will try to cover it up in upcoming articles with examples. For now, Let me just give you an overall idea and code how you can loop through it and create multiple records in a proper way.

: Code :


while (update_array.length > 0) {
await table.createRecordsAsync(update_array.slice(0, 50));
update_array= update_array_1.slice(50);
};

So, In here we are removing 50 records and only submitting 50 records for the operation and it's a good practice. I already have explained the word await in previous articles so you can refer to those for learning as well.

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

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

COPYRIGHT © 2022 · Monino Solutions ·