Reference Query Variable In Response

Hey everyone,

So I'm using an external API for pdf generation, and I have to generate an undefined number of pdf's each time, and so I've made it so it scales:

The promise that calls the query multiple times:

The query:

All of this works fine and generates the pdf's correctly.

For separate functionality in my application, however, I need to have each of the returned pdf's "attached" to the individual query that called it, namely with the "load_number" hopefully attached.


The best way I can think to do this would be to construct the response object in a way that it also includes a reference to a variable from the query that called it. However, when I attempt to reference the "apitemplate_dtnppa.body[whatever index the variable is]", regardless if its before or after the query, the value is always an empty string. The same can also be said of the, "apitemplate_dtnppa.importedQueryInputs.variable9" reference.

Is there something I'm missing that holds that information and can successfully pass it into the response object? Am I doing it completely wrong and there is a different way?

Thanks in advance!

Hi @shane_d_gray were you able to solve this? If not, I can find out some more info for you to help you out!

I haven't been able to solve this yet.

Hey @shane_d_gray!

Sorry about the late reply. If you await the query in your JS call you should be able to access the data, something like

let promises = (item) => {
   const data = await query.trigger({additionalScope: {/*scope vars*/}});
   /*process data.body[index] here*/

I would also expect you to be able to reference each individual query in the array returned at return Promise.all(promises) though. Let me know if that helps or if there's something I'm missing here!

Hey @Kabirdas, thanks for the reply.

I don't believe the timing of the promise is the issue that I'm running into. I'm not attempting to access any returned values from the individual queries in this case; I'm attempting to have access to one of the variables defined in "additional scope" in a way that when each query runs within the promise the response object has access to the variable, and can then provide basically a snapshot of that variable as each query runs, which I hope could attach that variable (which is unique in each query) to that response object.

This is what I get when the JS Query which has the over encompassing promise finishes:

As you can see, I already have access to each individual queries response object. This is what those objects look like:

The "load_number" key is a value I'm adding on myself, using the query response transformer I have an image of in my original post. Right now it's just full of nonsense; it's just there to show that I can manipulate the response objects of each query in the promise.

What I am ultimately trying to do is have that key in each queries response object contain the "load_number" variable provided in the additionalScope. I am not sure how to access this.

I ended up figuring it out, ultimately with your help by simply changing how I was returning each individual promise in the batch.


I just needed to see it returned a different way to see the scope in which I would be allowed to attach the variable to the response.