additionalScope not working in query trigger

  • Goal: To get multiple results from a query based on an array of data using a JS Query.

  • Steps:
    I have a REST query set up like this:

There are no other parameters… just that one in the URL.

In my app I have:

  1. An instance of that query, named “distinction_healthchecks”.
  2. A variable that returns an array of strings from another source named “health_checks”
  3. A javascript query as follows:

When I run this JS query, the logging shows that the “distinction_healthchecks” queries being executed are hitting the URL https://my-health-check-domain.com/_health-undefined despite the additional containing a valid string value.

Hi @leec,

I'd need to see your distinction_healthchecks function setup to know for sure what might be causing your issues, but assuming it is indeed configured properly and returns data as expected, try the following simplified code to see if it helps with debugging.

const codenames = health_checks.value
if (codenames.length === 0) return []

const promises = []
for(const codename of codenames) {
  const params = {client_healthcheck_name: codename}
  promises.push(distinction_healthcheck.trigger( { additionalScope: params } ))
}
const rawData = await Promise.all(promises)

const mergedData = rawData.map(d => d.data) // Because they all come out on the data property of the resolved data, this just cleans it up

return mergedData

You can log out the rawData to help with debugging and see if you can narrow down if something is going wrong.

Thanks for the reply @MikeCB

distinction_healthchecks is a REST resource query. It works fine if I give it a client_healthcheck_name value in the query pane:

The query is a simple GET request to a URL with the structure https://my-health-check-domain.com/_health-{{client_healthcheck_name}}

The issue seems to be that when called from a JS Query using additionalScope to pass the parameter, the parameter never actually gets passed so the query sends the GET request to https://my-health-check-domain.com/_health-**undefined** which, of course, returns a 404.

For anyone else that finds this, the answer is to add your parameters as variables in the query pane.

In my case this meant I needed to enter {{client_healthcheck_name}} into the client_healthcheck_name parameter field on the distinction_healthchecks REST query.

This will show red as an unknown variable but will work when called from the JS query.

This is super counter-intuitive and not covered in the official documentation.

3 Likes

Hi @leec, welcome to the forum! :wave:
Thank you for updating your topic with your solution! :slightly_smiling_face: