Help

Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

Currency Conversion Script - Run on Input?

329 4
cancel
Showing results for 
Search instead for 
Did you mean: 
Jon_Wright
5 - Automation Enthusiast
5 - Automation Enthusiast

I am using a modified version of the currency conversion script kindly provided in this thread https://community.airtable.com/t5/development-apis/custom-currency-calculations-using-scripting-pane... by @Vivid-Squid but I don't want to have to run the script each time and select which record I want it to run on. What I'm after is that when I input an amount in the 'Amount (GBP)' field it automatically runs the script to populate the 'Amount (Home Currency)' field.

Any ideas how I do this?

My script looks like this (it basically converts an amount in GBP to equivalent amount in the users local currency):

 

 

let table = base.getTable('Currency');
let record = await input.recordAsync('Pick a record', table);
let currencyType = record.getCellValueAsString("Local Currency");
let apiResponse = await fetch(`https://api.exchangerate.host/latest?base=${currencyType}`);
let data = await apiResponse.json();
let conversionRate = data.rates.GBP;
let result = await table.updateRecordAsync(record.id, {'Amount (Home Currency)':  record.getCellValue('Amount (GBP)')/conversionRate});

 

 

My table looks like this:

Screenshot 2022-12-09 at 15.46.45.jpg

 

 

4 Replies 4

Hi Jon,

This was a modification to the example script that ships with Airtable. The script you are looking for can be found in the examples section of the script editor.

Thanks for response. Do you mean this one https://airtable.com/developers/scripting/examples/currencyconverter ? If so, I tried that first and couldn't get it to do what I want. How would I modify either script to give me the results I'm after?

This was a change to the model content that boats with Airtable. The content you are searching for can be found in the models segment of the content supervisor.

Hi @Jon_Wright , 

Isn't an automation what you're looking for? You would have:

  1. Trigger = "when record updated" (watching field Amount (GBP))
  2. Run a script (you need to modify your code a little bit, let me know if you need help with that)
  3. Update record