Hello!
I’m populating my base with data from an external API and would like to update it regularly as new results come in without creating new duplicate records. I’ve read a couple of other topics that discuss that (like this one and this one), but am still struggling to figure it out.
I’m using the [uri] field in the base records and trying to match them to the array of [uri]s from the api. If there’s a match, the record would update, and if not, a new one would be created.
FWIW my knowledge of js is survivalist at best! Here’s what I have so far:
// The loop for each result in the API
for(let i = 0, l = data.results.length; i < l; i++) {
// ids for current records
let table = base.getTable("Observation");
let queryResult = await table.selectRecordsAsync();
const records = queryResult.records;
for(let i = 0, r = queryResult.records.length; i < r; i++) {
// grab cell value uri for reference against the api
let record = queryResult.records[i];
let cellUri = record.getCellValue("uri");
if (cellUri && data.results[i].uri) { // compare field and api
// update record
} else {
// create record
}
}
I’m getting way too many results for the update record function because of the double-loop, and nothing for the create record function, which means I’m probably setting this up wrong. Can anyone help me correct my code?
Thank you!
