How To Convert Currency in Airtable Script

If you had the chance to follow all the previous lessons, then you have already learned all the important operations [CRUD] in Airtable scripting. And if you are enjoying the series, don’t forget to share it with your friends. In these following lessons, I will explain to you various other use cases for Airtable scripting. In this lesson, I will explain how to convert different currencies in an Airtable script.

First, let’s discuss the current base and table on which I am performing currency conversion operations. It’s important, because if you are following me and your table is not the same as mine, then the script won’t work.

Currently, I have a table called “Currencies” and in this table, there are three columns:

  1. AMOUNT IN USD,
  2. In INR
  3. IN EURO.

So, When I create an entry in this table, I will only add the value to the first column which is “AMOUNT IN USD”. The other remaining values will be filled out automatically by our script.

airtable scripting script airtable how to convert currency in airtable script currency convert in airtable script convert currency in airtable

Steps to execute the script

  1. Install the scripting app if you already haven't installed it.
  2. Copy and paste the below code into your scripting app.
  3. Run the script.

: Code :


/* -------------- Selecting the table -------------- */let table = base.getTable('Currencies');
/* -------------- 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;
/* -------------- Getting current table data -------------- */let result = await table.selectRecordsAsync();
/* -------------- Updating data -------------- */for (let record of result.records) { await table.updateRecordAsync(record, { 'In INR': record.getCellValue('AMOUNT IN USD') * conversionRateINR, 'IN EURO': record.getCellValue('AMOUNT IN USD') * conversionRateEURO, });}

Understanding Code:

Let’s understand what exactly I am exactly doing in the code above:

  1. Firstly, I am selecting the table “Currencies”.
  2. Then I am getting currency data from the API. You can choose any API you want.
  3. Once I have the data, I am using the data based on my needs. Here I am converting USD to INR and USD to EUR.
  4. Finally, I am getting our current table code and updating it by iterating through a loop.

Isn’t it quick and simple? Just get the currency data from the API, then use that data to convert and update records. Here we are selecting data based on USD from the API and converting it to INR & EUR.

I hope this was helpful for your Airtable scripting journey and stay connected for more useful learning lessons.

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

monino solutions logo

COPYRIGHT © 2024 Monino Solutions.