Pass parameters to event handler

Surprised this one hasn't been suggested yet (let me know if I just didn't see it.)

When an event triggers a query it would be very helpful to pass some parameters like we can do using additionalScope when calling from javascript.

I see it looking like this:


This is useful when you want to use the same query to do that same action but with different data depending on where it was called from.

Right now you can use triggeredById in your query to find out what triggered the query and take certain actions like this:

  // Event Handler
  var contractor_id
  if (triggeredById === 'btnAssign') {
  if (triggeredById === 'btnAccept') {
  let assign = await qryTaskAssign.trigger({additionalScope: {contractor_id: contractor_id}})

Or something like this in a SQL query:

Update tasks set contractor_id=
`{{triggeredById === '' ? lstContractorAssign.value : lbOnJobBoard.value}}`
where task_id={{taskData.value.task_id}}

If you could pass a parameter things would use a more familiar pattern and be easier to reason with:

Param to Pass on btnAssign event handler: {contractor_id: lstContractorAssign.value}

Param to Pass on btnAccept event handler: {contractor_id: lbOnJobBoard.value}

  // Event Handler
let assign = await qryTaskAssign.trigger({additionalScope: {contractor_id: contractor_id}})


Update tasks set contractor_id={{contractor_id}}
where task_id={{taskData.value.task_id}}

@bradlymathews, you can use the action "Run script" instead of "Control query" and then pass your parameters to the query by using the additionalScope. What you are requesting is the same functionality but in the action "Control query" which doesn't add any real new functionality for developers (since the same exists already in "Run script"). It only makes Retool more attractive and easier to use for new developers since it is easier to spot the possibility to handover parameters to queries. Is my assumption correct?



Nice workaround!

I have barely used the Run Script option preferring to use separate js queries and transformers for all my code that is more than simple ternaries. In my view the more you can keep your code in one place (the queries list in this case) the better. If you have bits of code scattered all over your app in various components, it makes it more difficult to debug since it is harder to find.

Now if I could keep all of my related JS, SQL queries and transformers in a single file like I do when I build C# classes in Visual Studio, I would be a very happy camper!

For that reason I do still think that having a separate property to pass additionalScope parameters to queries making Control Query equal to query.trigger() would be preferable.


Another thing I would like to add is by my understanding purpose of retool is to make life easy. Yes you can run a script then you can do almost everything by hand.

So little things matter now a days.


Was this ever implemented? I second the last opinion, it would make life easier. Having scripts everywhere to call queries with different parameters makes things very messy.

1 Like

Not yet @pablitador, for now scripts are still the best way to go!

This is available now.

If you set Additional Scope in the query:


You will now see these as options when you trigger that query in an event:


Awesome Sauce!