Dec 09, 2022 07:49 AM - edited Dec 09, 2022 07:51 AM
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:
Dec 09, 2022 08:55 AM
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.
Dec 09, 2022 09:15 AM
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?
Dec 09, 2022 09:15 PM
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.
Dec 12, 2022 12:31 AM
Hi @Jon_Wright ,
Isn't an automation what you're looking for? You would have: