Skip to main content
Version: 2.0.0

Run Actions from RunJS query

Now you can trigger all the actions available in ToolJet from within the RunJS query. This guide includes the syntax for each action along with the example.

Run Query

Syntax:

queries.queryName.run()

or

await actions.runQuery('queryName') 

Example: In the screenshot below, we are triggering the two different queries customers and getData using the two different syntax available for Run Query action.

ToolJet - How To - Run Actions from RunJS query

Set Variable

Syntax:

actions.setVariable(variableName, variableValue)

Example: In the screenshot below, we are setting the two variables test and test2. test variable includes a numerical value so we haven't wrapped it inside the quotes but the variable test2 is a string so we have wrapped it in quotes.

ToolJet - How To - Run Actions from RunJS query

Unset Variable

Syntax:

actions.unSetVariable(variableName)

Example: In the screenshot below, we are unsetting the variable test2 that we created in the previous step.

ToolJet - How To - Run Actions from RunJS query

Logout

Syntax:

actions.logout()

Example: Triggering actions.logout() will log out the current logged in user from the ToolJet and will redirect to sign in page.

ToolJet - How To - Run Actions from RunJS query

Show Modal

Syntax:

actions.showModal('modalName')

Example: In the screenshot below, there is a modal on the canvas (renamed it to formModal from modal1) and we are using RunJS query to show the modal.

ToolJet - How To - Run Actions from RunJS query

Close Modal

Syntax:

actions.closeModal('modalName')

Example: In the screenshot below, we have used RunJS query to close the modal that we showed up in previous step.

ToolJet - How To - Run Actions from RunJS query

Set Local Storage

Syntax:

actions.setLocalStorage('key','value')

ToolJet - How To - Run Actions from RunJS query

Copy to Clipboard

Syntax:

actions.copyToClipboard('contentToCopy')

ToolJet - How To - Run Actions from RunJS query

Generate File

Syntax:

actions.generateFile('fileName', 'fileType', 'data')

fileName is the name that you want to give the file(string), fileType can be csv, plaintext, or pdf and the data is the data that you want to store in the file.

Example for generating CSV file:

actions.generateFile('csvfile1', 'csv', '{{components.table1.currentPageData}}') // generate a csv file named csvfile1 with the data from the current page of table

Example for generating Text file:

actions.generateFile('textfile1', 'plaintext', '{{JSON.stringify(components.table1.currentPageData)}}') // generate a text file named textfile1 with the data from the current page of table (stringified)

ToolJet - How To - Run Actions from RunJS query

Go to App

Syntax:

actions.goToApp('slug',queryparams) 
  • slug can be found in URL of the released app after the application/, or in the Share modal
  • queryparams can be provided like this [{"key":"value"}, {"key2":"value2"}]

ToolJet - How To - Run Actions from RunJS query

Show Alert

Syntax:

actions.showAlert(alert type , message ) // alert types are info, success, warning, and danger

ToolJet - How To - Run Actions from RunJS query

Run multiple actions from runjs query

To run multiple actions from a runjs query, you'll have to use async-await in the function.

Here is an sample code for running the queries and showing alert after specific intervals. Check the complete guide on running queries at specified intervals here.

actions.setVariable('interval',setInterval(countdown, 5000));
async function countdown(){
await queries.restapi1.run()
await queries.restapi2.run()
await actions.showAlert('info','This is an information')
}