How to pass parameter from Javascript to SQL query?


I'm trying to pass a parameter from a Javascript query to a SQL query. I am using this approach because I would like the Javascript query to call multiple SQL queries.

I've read Scripting Retool and a couple of other forum posts but can't seem to make it work.

This is what I have so far

The SQL query is defined as below and is named users_sql_reset_account_onboarding_state:

UPDATE "user"
SET current_step = 1
WHERE email IN ({{email}});

The Javascript that calls the user query is defined below:

  additionalState : {

The query executes without error but is not replacing {{email}} with the actual email. I know this because I replaced the {{email}} in

WHERE email IN ({{email}})

with some random variable name {{bob}}

WHERE email IN ({{bob}})

and the query still ran with no errors.

How do I pass the email address from the JS to the SQL?

I do not want to set the Disable converting queries to prepared statements setting.

If it's only one email being passed in you don't need to use IN and remove the quotes

SET current_step = 1
WHERE email = {{email}};

But all over, your code looks correct. Maybe file this under support as well.

Thanks. What's the best way to contact support?

Either tag this post as support or use the chat option on the bottom right of the platform

1 Like

I think you want additionalScope, no?

1 Like

Yep, didn't notice that.... good work @bca

1 Like

If I could give out ten :star: I would. Thanks a million @bca :pray:

1 Like