Reference Error in Workflow

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.

This is how I have it:

I created the function

Tried to call with JS. It says bad request due to decryption failure. This happened most likely due to what is passed as currentBatch

const batchSplitData = batchSplit.data;
const submitResults = [];

for (let i = 0; i < batchSplitData.length; i++) {
  const currentBatch = batchSplitData[i];

  // Wrap the trigger call in a function to correctly capture the current value of `i`
  const submitPromise = ((batch, index) => {
    return submitCreditInfo({
      additionalScope: {
        currentBatch: batch,
        userid: 'crcautomations'
      }
    }).then(response => {
      if (response.success) {
        return `Batch ${index} submission successful: ${JSON.stringify(response.data)}`;
      } else {
        throw new Error(`Batch ${index} submission failed: ${response.error}`);
      }
    }).catch(error => {
      return `Batch ${index} submission failed: ${error.message || JSON.stringify(error)}`;
    });
  })(currentBatch, i);

  submitResults.push(submitPromise);
}

// Use Promise.all to wait for all submissions to complete
return Promise.all(submitResults);

I went on to try a batch of the data directly in the workflow and it was successful