Trigger Query, additionalScope not working

Trying to trigger a firebase query from JS query.
First query is a JS query which I am calling from a map field on a table.
`// Lets grab the IDs from the selected row in the table

let categoryIds = youtubeChannelsTable.selectedRow.data.channels_categories;
let categoriesStr = "";

console.log(categoryIds);

categoryIds.forEach(function(catId){

console.log("Cat ID: "+catId);

getChannelById.trigger({
additionalScope: {
catId: catId,
},
onSuccess: function(data){
console.log("Start");
console.log(data);
console.log("Stop");
},
onFailure: function(error) {
console.log("Something happened, refresh the table");
console.log(error);
}
});
});`
This query works just fine in the map. It loops through and console logs each value. The problem is it triggers the second query just fine but I am not able to use the additional scope of "catId" Was curious if anyone has any ideas?
My second query looks like this:




For whatever reason its not able to use the additional variable thats set with the additional scope? Any help would be appreciated.

Getting the same issue.

Sorry for the late reply here but I want to get details for future people that find the post. The JS setup here looks correct, i’m curious what kind of return this second query was giving.

One note in general is that the UI will always show {{catId}} here as “is not defined” since the value only exists when created by the JS code and passed in as additional scope. When the query runs, it checks to see if any additionalScope was given to it, and then if any undefined values in the query are inside of the additionalScope.

If you look at the query triggering action in the browser console. you can see the additional scope objec that is being passed. If that looks good, the next troubleshooting step I would do here is to confirm that the id value that the Firestore query is sending is undefined, and then try sending a hard coded string to confirm that the query/connection itself works.

Helle there,

I’ve been running into the same issue. I am trying to run querries from a js script but no matter what I pass to the additionalScope object (that do appears properly in the console) my request doesn’t work. When I try with a raw string instead, it works.

1 Like

Has there been any update on this? I'm also running into this issue - trying to use an a variable passed with additionalScope in the URL path, but when the query is executed it gets a 400 because it's "undefined". In console I see the correct string being passed but something breaks on the way to the triggered query.

1 Like

Hi loic.alleyne!

This should be working correctly, could you share an example of your queries?

ok, well now I've got the additionalScope being passed correctly but at the query that's being triggered I want to use the additionalScope variable in an url parameter.
In this particular use case I'm trying to paginate through an API where I specify the page in an url parameter; I need to default to page 1 and then trigger page up or down with additionalScope. I keep running into errors saying that the variable is not defined.

The API will return page one if the "page" url parameter is not included, but so far I haven't found a way to completely disable a parameter, if I put a condition to make it null it shows up as '/?=' in the url and the call fails.

I've tried to work around this by using a transformer or a js function query to generate a string to append to the API url, but the '?' and '&' get url encoded and the whole thing fails as well.

I'm currently running into this same issue. I am trying to pass additionalScope from a JavaScript Query to a PostgreSQL query (non-GUI). I see the correct values assigned to the additionalScope in the browser's dev console, but the query always throws the "is not defined" error.

UPDATE: I was able to resolve my issue and I believe it was related to async dependencies--possibly the resolution of a promise.

I originally was calling an API query and had configured its onSuccess handler to call a JS query that referenced the data from the API query. Once I switched it to initiate from a JS query that called the trigger function of the API query and then passed the remaining logic to the onSuccess parameter [of that trigger function], it started working as expected. I'm not sure if this intended behavior or not, but hopefully it helps someone facing similar issues.

2 Likes

I am also seeing this issue. Was this ever resolved? Or was a root cause ever determined?

I have a REST API query, which works just fine when it is run directly (by pressing the Run button). I have dumped the variables that I am using in the additional scope to local storage, and they look correct, but it the query is not producing the correct results when run by calling the query through a javascript.

UPDATE: I just noticed that kyle.hicks was able to resolve their issue, but I still do not understand how to fix my problem. I was already using the additionalScope, onSuccess and onFailure of the trigger function. I can tell that my code is waiting for the query to complete before triggering again, as the local storage variable dumps are delayed, indicating that the script is waiting for the previous query to complete before continuing.

Hey @nl-setech! Happy to help with this. Would you mind sharing a few screenshots of your queries involved?

I was able to get something working, although I never figured out why I couldn't pass in variables using additional scope. Future readers can read: REST API results differ when called directly versus from javascript - #10 by nl-setech for a workaround.