How To Update records through Airtable Scripting

Till now, I already explained to you how to select records and how to insert records in airtable scripting app in previous articles. In this article, I am explaining to you how to update records through airtable scripting app.

The first step is to install the scripting app in airtable. Once you have the app, Copy the code and Paste into your app. Consider below structure of the table before using the code. If your structure is not the same, You might face errors while executing.

airtable scripting app how to update records through airtable scripting updating records in airtable script update records in airtable scripting app how to update records in airtable

: Code :


let table = base.getTable('Teachers');
let table_data = await table.selectRecordsAsync();
let update_array = table_data.records.map(record => {return {id: record.id,fields:{'Name':record.getCellValue('Name'),'Class': record.getCellValue('Class'),'Max Students Allowed': 10,'is spare teacher?': false}}});
while (update_array.length > 0) {await table.updateRecordsAsync(update_array.slice(0, 50));update_array = update_array.slice(50);};


// await table.updateRecordAsync(update_array[0].id, {// 'Name': 'Smit Patel',// 'Class': '5th Standard',// 'Max Students Allowed': 10,// 'is spare teacher?': true// })

Understanding Code:

In the above code, we are configuring the table and getting data from a table. Then we are using a JavaScript function to create a new array and finally update records by going through a loop.

For the Update operation, Just like the select operation, we have two functions.

  1. Single record update function: updateRecordAsync()
  2. Multiple records update function: updateRecordsAsync()

The first function is used to update a single record and the second function is for multiple records. I have given an example of the second function. For the first function, you can refer to the commented code.

In the First function, you need to pass two parameters

  1. Record ID
  2. Data to be updated.

I am using the map function of JavaScript and using this function I am creating a new array with a specific format. In this new array, I am using old data from a table and with some modifications creating a new array. For this example, I used old data from airtable for the 'Name' and 'Class' fields and updated the 'Max Students Allowed' and 'is spare teacher?' fields with fixed values. So, Only two fields will be updated in airtable 'Max Students Allowed' and 'is the spare teacher?'. Finally, go through a loop and update records. It's as simple as that, Just need to understand the format.

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.