Js call Retool RPC with arguements

Hello!

  • Goal: Make javascript query that call retool rpc.

  • Steps:

  1. Given retool RPC Query which require arguments, write javascript Query that call retool Query.
  2. In the code, trigger retool RPC Query.
  3. You'll see an error message that arguments are required.

Thanks.

Hi @sol, welcome to the forum! :wave:

It looks like we are just missing one step. When setting up arguments for the Resource, the value for the key 'addresses' is what we'll set data for using 'additionalScope.' For example, if we set the value as {{ foo }}, we would trigger the query using this additionalScope:

query.trigger({
  additionalScope:{
    foo: "helloWorld"
  }
})

Because the value for the key 'addresses' is {{ foo }}, "helloWorld" would become the value for 'addresses.' Just add a value for that key and it should work:

sol-screenshot

1 Like

Thanks for answer!

Used variable(test_variable) to pass the value, but I'm still having trouble.
It seems that setting a variable with additionalScope sets an empty value to the variable. (attached image #2).

I wonder if there is a bug in the RPC related function, for now, I solved it by assigning the values directly before calling trigger in the js script. (attached image #3).

1

2 variable in additionalScope

3

On the resource settings:

Change {{ test_variable.value }} for {{ test_variable }} . Additional scope is a bit different than referencing the value of a State variable.

And don't use a State variable at all.

Remove line 2 from here and delete the State variable.

Here is an example on how to use additional scope:

On the resource settings, we set the key-value pair.

In this case {{ transactionId }} will take the value we pass using additionalScope

When we trigger the query, we set a key-value pair where the key is the variable 'declared' on the resource settings, and we set the value for it:

1 Like

It works! Thank a lot Paulo.

You are welcome! :slightly_smiling_face: