I am struggling with a piece of code trying to load data from an external datasource via API-call to a Retool-database. The code looks as follows:
queryExpensesFullSync.trigger({
onSuccess: function (data) {
data.expenses.forEach(row => {
updateExpensesFullSync.trigger({
additionalScope : {
expense_id: row.id,
spent_date: row.spent_date
}});
//console.log("Row.id = " + row.id);
}
);
},
onFailure: function (error) {
console.log(error);
},
});
- queryExpensesFullSync: External API-Call getting a substantial amount of data
- updateExpensesFullSync. SQL Query inserting/updating new/existing records in a Retool database
The operation seems to fail because there are too many parallel calls of updateExpensesFullSync.trigger
(if I reduce the number of records to be processed by changing the API call, it works just fine).
Now I wonder how I can make sure that only one call is made at a time. I fiddled around with Javascript Promises (also looking at this: Await for a query to finish) but don't get it to work. Any help is highly appreciated.