Run Script
Use this widget action to configure script execution directly from the dashboard.
The script may require you to define input methods. Script launch parameters vary depending on the widget used.
The Run Script action resembles running a script from the dashboard. The difference is that this action supports a limited set of input methods, and no parameter input form appears before script execution.
For more information about action configuration parameters, see Running a Script from the Dashboard.
Usage Example
Consider how the Run Script action can transfer data from one table to another and remove it upon clicking a button in Browse mode.
- Add two tables to the Data Model —
product_salesandnew_product_sales. - Create a script to handle populating data from the
product_salestable intonew_product_sales(named Importing data in this example). The script has two blocks. The first one is Manual start. Add the block and test it. Add the second block, SQL query, which would execute the query upon run. The query for the block:CREATE OR REPLACE TABLE new_product_sales ENGINE MergeTree() ORDER BY tuple() as select * from product_sales - Publish the script.
- Create the second script (named Remove imported data in this example) for clearing the table. The query for the block:
truncate new_product_sales - Test the block and publish the script.
- Add Button and Table widgets to the view.
- Name the first button Import data. Assign the Run Script click action to it and select the Importing data script. In the Auto update parameter select the All views option.
- Name the second button Remove data. Assign the same click action and select the Remove imported data script. In the Auto update parameter select the All views option.
- In the Table widget add all the columns from the
new_product_salestable as dimensions. - Publish the dashboard.
- Now, in Browse mode, clicking the Import data button populates the table.
- Clicking the Remove data button restores the widget to its original, empty state.
Click Action in YAML
To add a click action (EXECUTE_SCRIPT), use the keys listed in the tables below. Specify these keys within the onClick block. Keys for the onClick block are described on the page Click Actions.
| Key | Type | Definition |
|---|---|---|
| scriptKey | string | Script key |
| autoUpdate | — | Auto update: - NONE — none- THIS_WIDGET — this widget- ALL_WIDGETS — all widgets |
If the script requires parameters, include a parameters block. Inside this block, use the name and inputMethod keys.
| Key | Type | Definition |
|---|---|---|
| parameters | — | Script parameters (optional key) |
| name | string | Parameter name |
| inputMethod | enum | Input Method value |
Example:
onClick:
- name: "Run Script"
type: EXECUTE_SCRIPT
scriptKey: script_9124125
parameters:
- name: Parameter 1
inputMethod: COLUMN
tableName: table_1
columnName: column_1
- name: Parameter 2
inputMethod: VARIABLE
sourceVariable: variable_10
- name: Parameter 3
inputMethod: FORMULA
formula: 'avg("table_1"."column_1")'
updateAfterExecution:
updateObject: CURRENT_WIDGET
Was the article helpful?