In this lesson, you will learn how to Handle Linked records and select options. Normal fields or columns can be very easy to handle but linked records and selection options of airtable can be complicated. This lesson is part 1 where I am only focusing on fetching the data. In the next lesson, you will learn how to insert or update linked records or select options data into airtable. So, Let's learn and understand how you can handle linked records and select options. First, Let's create linked records and select options in our tables. For this, we need two tables to link them together. Consider below two screenshots which are going to be two tables for this lesson.
2. Users data Table
In above tables, There are two fields which are important
Now, install scripting app in your base. Then you can copy and paste below script into your base.
let users_table = base.getTable('Users');
let users_table_data = await users_table.selectRecordsAsync();
let users_data_table = base.getTable('Users data');
let users_data_table_data = await users_data_table.selectRecordsAsync();
console.log('--------- Handling Select Options ---------');
for(let user of users_table_data.records){
console.log('Option Value: '+user.getCellValue('User type').name);
console.log('Option color: '+user.getCellValue('User type').color);
}
console.log('--------- Handling Linked Records ---------');
for(let user_data of users_data_table_data.records){
console.log('Record ID: '+user_data.getCellValue('User')[0].id);
console.log('Record Value: '+user_data.getCellValue('User')[0].name);
}
In above code,
Now, If you have noticed, when I am printing the data or accessing the data, I am using the name, color, and id to get specific values. Because while working with linked records, you will get the ID of the linked record and the value of a record. Also with the select option, you will get the id, value, and color of the option. Remember, when you will work with both types of fields, you need to make sure what exactly you are looking for. Sometimes you need to choose an only value or you might need the complete object that you get. Now, you can check out the below screenshot which is the output of the above script.
That's it for this lesson, In the next lesson, you will learn how you can insert or update linked records or select options records in airtable. Stay connected for more learning lessons. Feel free to contact me for Airtable consulting service by Clicking Here.