Hi everyone!
I have altered the example script a bit to update the ‘£ Rate’ field on all records in my ‘Cash Input’ table. I want the script to update the ‘£ Rate’ field only in new records that do not already have a value in the ‘£ Rate’ field. How can I do that? What changes does my code need?
I use this code:
let table = base.getTable('Cash Input');
// Fetch conversion rate from API - you could change this to any API you want
let apiResponse = await fetch('ttps://api.exchangeratesapi.io/latest?base=EUR');
let data = await apiResponse.json();
let conversionRate = data.rates.GBP;
output.text(`Conversion rate: ${conversionRate}`);
// Update all the records
let result = await table.selectRecordsAsync();
for (let record of result.records) {
await table.updateRecordAsync(record, {
// Change these names to fields in your base
'£ Rate':conversionRate,
});
}