Set additionalScope data to triggerQuery when called from a component

I'm working with a custom component that needs to trigger a query with some additionalScope data.

I'm getting the query to trigger with window.Retool.triggerQuery('save_new_print') but am unable to figure out how to pass data along that query call.

What am I missing?

1 Like

Any chance you can share what you are trying to pass into the query?

Here's what I have done with an onClick event on a button for adding Terms into a table:
This is the additionalScope trigger fired when clicking on the button
for(i=0;i<terms.value.length; i++){

insertTerms.trigger({
additionalScope: {
term1: somefield.value,
term2:somefield2.value,

},
onSuccess: function(data) {
console.log('Successully ran!');
},
onFailure: function(error){
console.log("Something broke");
},
})

}

//Here is the query
INSERT INTO terms(term1, term2) VALUES ({{term1}}, {{term2}})

Note the curly brackets at the end of the query are the values from the additionalScope

Hey @ScottR,

This would work if it was in a JS query but not in a custom component. With a component I need to call (afaik) triggerQuery which is available in the window.Retool object.

This works for example: window.Retool.triggerQuery('save_new_print') but unable to pass any additionalScope to that call. I'm probably missing the formatting here (how the data gets passed to the function)

2 Likes

Sorry about that - my bad. I haven't worked with a react component yet but in reading this page just now, it might help you?
https://docs.retool.com/docs/custom-react-components#prerequisites

No worries :slight_smile: read through all the docs but couldn't find anything :cry:

Hey minijohn, I'm happy to offer a suggestion here :grinning_face_with_smiling_eyes: In our docs on how to trigger queries from your custom component it suggests that you pass the data you want to be used in your query to your app separately using modelUpdate() and then reference that value in the query that is triggered. Could that work for your use case?

Hey @everett_smith,

Aware of this but doesn't work for my use-case unfortunately :cry: So is it right to assume that triggerQuery doesn't accept any parameters then?

If so, I'll change the implementation to work with modelUpdate

Hey minijohn, Unfortunately, no, triggerQuery doesn't accept parameters. Hopefully, you can make this work by passing your parameters with model and modelUpdate!

1 Like

Can't do this way, because every time model changed it will trigger model change event and rerender component

Hey, any update here from the Retool Team? This is a very sad limit, which makes it very hard to use custom components.

Hey @p0wl! Unfortunately, there aren't many updates to share here. The ticket hasn't been on the roadmap so far, it was recently bumped to get more eyes on it but I can't say when support will be added. For now, the best route is to have queries reference the custom component's model as mentioned above.