I want to submit records in batches via an a rest API block query_14. In my workflow order I created a JS block with the below code just before the API block
Error: Reference Error, query14 isnot defined. If I place query 14 before the JS block, it says the JS block is not defined
const resultBatches = [];
async function processBatch(batch) {
try {
await query14_lambda.trigger();
// Add the current batch to the result array
resultBatches.push(batch);
} catch (error) {
console.log('Error processing batch:', error);
}
}
// Iterate over batches
for (const batch of batchSplit.data) {
await processBatch(batch);
}
return resultBatches;
I was having trouble with the loop block as well. My solution was to turn the loop lambda into a Function over in the sidebar, then you can just use a regular code block and handle the loop yourself. I think the issue is we are relying on the loop block passing the values implicitly via the trigger. If you make it a function, you can pass the arguments yourself and await the result.