Handle Linked records and select options Part 1

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.

1. Users Table

handle linked records and select options linked records in airtable script select options in airtable script airtable script linked records airtable script select options

2. Users data Table

handle linked records and select options linked records in airtable script select options in airtable script airtable script linked records airtable script select options

In above tables, There are two fields which are important

  1. User Type [ Users table ]: - Select option
  2. User [ Users data table]: - Linked record

Now, install scripting app in your base. Then you can copy and paste below script into your base.

: Code :


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);
}

Understanding the code:

In above code,

  1. From line no 1 to 5: - I am fetching data from existing tables.
  2. From line no 7 to 11: - Going through a loop and printing select options.
  3. From line no 13 to 17: - Going through a loop and printing linked records.

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.

handle linked records and select options linked records in airtable script select options in airtable script airtable script linked records airtable script select optionshandle linked records and select options linked records in airtable script select options in airtable script airtable script linked records airtable script select options

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.

COPYRIGHT © 2022 · Monino Solutions ·