Help

Re: Currency Conversion Script - Run on Input?

1197 0
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?

dilshah
4 - Data Explorer
4 - Data Explorer

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.

Marielle_Gueis1
6 - Interface Innovator
6 - Interface Innovator

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