JS Query Additional Scope not recognized

A pattern I have used extensively in the past seems to be failing on me now.

I am trying to pass a parameter into a JS Query via additional scope and whilst the code completion in the query editor recognises the parameter, when I try run or test the query its says the parameter is not defined. See below for simplest example.

Has something changed ?

Using Cloud-hosted 3.329.0

1 Like

HEy @derek_c,

Would you mind sharing how you're triggering query1? Is it via script or the UI provided by Retool's event handlers?

1 Like

I was just using the Test / Run buttons which typically have worked in the past.

1 Like

Hey @derek_c

When using additionalScope, you need to pass the variable into that scope at the time you trigger the query.

In your example, you’re using the variable myParam. If you trigger query1 directly, it tries to access myParam without it being defined, which results in the error:

myParam is not defined

To avoid this, you’ll need to trigger the query from another query and pass myParam through additionalScope.
For example, I created a query called queryGet, where I simply log the value of myParam. Then, from another query (called runQuery), I trigger queryGet and pass the required data into additionalScope.

from another query i pass the additional scope data name is runQuery

When you run runQuery, it automatically provides the scoped data to queryGet, like this:

await queryGet.trigger({
  additionalScope: {
    myParam: "123",
  },
});

In another way you can also pass the data into the additional scope from the event handler or in button where you can pass the data in it like this you have to pass the key into the additional scope of the query like i pass into the runQuery


In the button i trigger the query runQuery and pass the additional scope directly from the event handler

Hope it will work for you.

1 Like

Thanks so much for your response - that all works. I appreciate your effort.

I guess the answer is that once you declare additionalScope variables for a JS Query you cannot really test that query’s functionality in isolation (ie using Test/Run) without triggering the query from another component or query. I couldn’t find a way to pass sample data into the definition of the query itself.

2 Likes

Hi @derek_c,

Yes that is correct, when testing, it is a bit tedious to have to hook the query to a trigger where additionalScope is passed in programmatically from another query as shown in @WidleStudioLLP's example.

We are working on a project for Retool Functions that will be able to take in arguments from the query panel window which will effectively allow for the functionality you are describing. I can add your +1 to the ticket on that project!

3 Likes