Skip to main content

Currency Conversion Script - Run on Input?


Forum|alt.badge.img+5

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-panel/td-p/136067 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:

 

 

4 replies

Forum|alt.badge.img+16
  • Inspiring
  • 532 replies
  • December 9, 2022

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.


Forum|alt.badge.img+5
  • Author
  • Inspiring
  • 7 replies
  • December 9, 2022
Vivid-Squid wrote:

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?


Forum|alt.badge.img
  • New Participant
  • 1 reply
  • December 10, 2022

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.


Forum|alt.badge.img+7
  • Participating Frequently
  • 17 replies
  • December 12, 2022

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 

Reply