mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-21 21:47:17 +00:00
204 lines
4.7 KiB
Markdown
204 lines
4.7 KiB
Markdown
---
|
|
id: run-actions-from-runjs
|
|
title: Run Actions from RunJS query
|
|
---
|
|
|
|
# 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:**
|
|
|
|
```js
|
|
queries.queryName.run()
|
|
```
|
|
or
|
|
```js
|
|
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.
|
|
|
|
<div style={{textAlign: 'center'}}>
|
|
|
|

|
|
|
|
</div>
|
|
|
|
### Set Variable
|
|
|
|
**Syntax:**
|
|
|
|
```javascript
|
|
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.
|
|
|
|
<div style={{textAlign: 'center'}}>
|
|
|
|

|
|
|
|
</div>
|
|
|
|
### Unset Variable
|
|
|
|
**Syntax:**
|
|
|
|
```javascript
|
|
actions.unSetVariable(variableName)
|
|
```
|
|
|
|
**Example:** In the screenshot below, we are unsetting the variable `test2` that we created in the previous step.
|
|
|
|
<div style={{textAlign: 'center'}}>
|
|
|
|

|
|
|
|
</div>
|
|
|
|
### Logout
|
|
|
|
**Syntax:**
|
|
|
|
```javascript
|
|
actions.logout()
|
|
```
|
|
|
|
**Example:** Triggering `actions.logout()` will log out the current logged in user from the ToolJet and will redirect to sign in page.
|
|
|
|
<div style={{textAlign: 'center'}}>
|
|
|
|

|
|
|
|
</div>
|
|
|
|
### Show Modal
|
|
|
|
**Syntax:**
|
|
|
|
```javascript
|
|
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.
|
|
|
|
<div style={{textAlign: 'center'}}>
|
|
|
|

|
|
|
|
</div>
|
|
|
|
### Close Modal
|
|
|
|
**Syntax:**
|
|
|
|
```javascript
|
|
actions.closeModal('modalName')
|
|
```
|
|
|
|
**Example:** In the screenshot below, we have used RunJS query to close the modal that we showed up in previous step.
|
|
|
|
<div style={{textAlign: 'center'}}>
|
|
|
|

|
|
|
|
</div>
|
|
|
|
### Set Local Storage
|
|
|
|
**Syntax:**
|
|
|
|
```javascript
|
|
actions.setLocalStorage('key','value')
|
|
```
|
|
|
|
<div style={{textAlign: 'center'}}>
|
|
|
|

|
|
|
|
</div>
|
|
|
|
### Copy to Clipboard
|
|
|
|
**Syntax:**
|
|
|
|
```javascript
|
|
actions.copyToClipboard('contentToCopy')
|
|
```
|
|
|
|
<div style={{textAlign: 'center'}}>
|
|
|
|

|
|
|
|
</div>
|
|
|
|
### Generate File
|
|
|
|
**Syntax:**
|
|
|
|
```javascript
|
|
actions.generateFile('fileName', 'fileType', 'data')
|
|
```
|
|
|
|
**Example:** `fileName` is the name that you want to give the file(string), `fileType` can be `csv` or `text`, and `data` is the data that you want to store in the file.
|
|
|
|
<div style={{textAlign: 'center'}}>
|
|
|
|

|
|
|
|
</div>
|
|
|
|
### Go to App
|
|
|
|
**Syntax:**
|
|
|
|
```javascript
|
|
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 `[ ['key1','value1' ], ['key2','value2'] ]`
|
|
|
|
<div style={{textAlign: 'center'}}>
|
|
|
|

|
|
|
|
</div>
|
|
|
|
### Show Alert
|
|
|
|
**Syntax:**
|
|
|
|
```javascript
|
|
actions.showAlert(alert type , message ) // alert types are info, success, warning, and danger
|
|
```
|
|
|
|
<div style={{textAlign: 'center'}}>
|
|
|
|

|
|
|
|
</div>
|
|
|
|
## 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](/docs/next/how-to/run-query-at-specified-intervals)**.
|
|
|
|
```js
|
|
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')
|
|
}
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|