Category: How do I do X?

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

How do I conditionnaly run a query from text in an input widget?


I was trying to conditionally run a query based on text input in an app. I had an input widget called flash and two queries called transport 1 and transport 2. I wanted to run transport 1 if the user entered flash >= 145, otherwise run transport 2. However, my initial code did not work. With some help and guidance from the documentation, I was able to fix the syntax and use async/await to make the JS function work as expected.


The solution involves creating a JS function that conditionally runs one of two queries based on the text input in an input widget. If the user writes a value equal to or greater than 145, then the first query is run and the dataset is saved using the storeValue() method. If the value is below 145, the second query is run and its data is also saved using storeValue().

To make sure the function runs as expected, async/await is used to await the query run and storeValue() method since they are both async functions. The final code example includes the use of async/await and correct syntax for the storeValue() method. Proper documentation on using async/await and JS promises is also provided.