Exchange rate table
An exchange rate is given for each currency, within each month’s data rage
Project details tables
Shows the project start date and currency
I’m trying to write a script that:
- Looks at each project ID, its currency and start date
- Then looks at the Exchange rate table, matches the currency and finds the right date range that the Project start date fits into
- (The exchange rate table only has rates for past months. So if the Project start date isn’t in a date rate in the table, it should take the latest date for that currency)
- Then in the Project details table includes the correct exchange rate in the field Exchnage rate
My current code is:
let mainTable = base.getTable("Project details");
let maintTableRecords = await mainTable.selectRecordsAsync({fields:["Project start date"]});
let lookupTable = base.getTable("Budgeting exchange rates");
let lookupRangeRecords = await lookupTable.selectRecordsAsync({fields:["Start date","Exchange rate"]});
for (let record of maintTableRecords.records) {
let lookupValue = record.getCellValue("Project start date");
for (let rangeRecord of lookupRangeRecords.records) {
if (rangeRecord.getCellValue("Start date") === lookupValue) {
let returnValue = rangeRecord.getCellValue("Exchange rate");
await mainTable.updateRecordAsync(record, {
"Exchange rate": returnValue
})
}
}
}