How To Take User Input in Airtable Script

Welcome to lesson 7 of my Airtable scripting series. In this lesson, I will go through how to Take User Input in your Airtable Script. There are two ways to take user input:

  1. Directly: Using the script, and selecting a record from there.
  2. Indirectly: Create a button in your table and click on it.

I will explain both ways in this lesson. First, let’s understand the direct way Firstly, you need to install the scripting app, then you need to copy and paste the code below into your app. For this lesson, I am using the previous lesson’s table and code. You can click here to read the previous lesson.

: Code :


/* -------------- Selecting the table & Getting selected record data -------------- */
let table = base.getTable('Currencies'); let record = await input.recordAsync('Select a record to use', table);
/* -------------- Getting data from API -------------- */
let apiResponse = await fetch('https://api.exchangerate.host/latest?base=USD');
/* -------------- USING API DATA -------------- */
let data = await apiResponse.json(); let conversionRateINR = data.rates.INR; let conversionRateEURO = data.rates.EUR;
/* -------------- Updating data -------------- */
await table.updateRecordAsync(record.id, { 'In INR': record.getCellValue('AMOUNT IN USD') * conversionRateINR, 'IN EURO': record.getCellValue('AMOUNT IN USD') * conversionRateEURO, });

If you are coming from the last article you might already have noticed that the code is exactly the same, with the exception of the second line. That is the only line of code you need to learn in this lesson. Here we are using 'input.recordAsync' which is used to take user input. We are passing two arguments:

  1. First Argument: Text that is displayed as a guide and for the user.
  2. Second Argument: Table which we previously selected.

Now you can run the script and once you run it, it will ask you to select an existing record from the table. Once you select the record, the script will do the remaining job. Let me explain the above code in steps:

  1. First we are selecting the table and then take user input that is any existing record.
  2. Then we are fetching data from the API for currency conversion.
  3. Once I have the data, it converts USD to INR & USD to EUR.
  4. At last we are updating the data.

Now, what if you want to take user’s input from a button click?

It’s simple, just create a new column in the table and choose the button as a type of column. In the button configuration, you just need to select 'run a script' as an action. The script will automatically take the clicked button’s record as user input and use it in the process. The image below shows how to configure the button action.

how to take user input in airtable user input in airtable scripting airtable script user input taking user input in airtable script how to get user input in airtable script

Stay connected for more learning lessons.

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

monino solutions logo

COPYRIGHT © 2024 Monino Solutions.