Update Variable
In this article
Use this action to change the value of a variable in the dashboard.
Note
It is impossible to update input values and system variables using this click action.
Usage Example
As an example, consider a dashboard that displays a product price after applying a discount.
- Two (Input Value#Dashboard Variables ../2.3.Add_setup_metric/2.Calculated_variable.md) variables are added to the dashboard: Discount and Discounted Price. The default value for Discount is 10, and for Discounted Price it is 0.
- Three widgets are added to the view: (Parameter ../2.1.Edit_mode/11.Variable.md), (Text ../2.1.Edit_mode/14.Text.md), and (Table ../2.1.Edit_mode/3.Tables.md).
- The Parameter widget displays the value of the Discount variable.
- The Text widget displays the value of the Discounted Price variable.
- The table shows product names and their prices. The Unit Price dimension has the Update Variable click action assigned. (Example screenshot 8 ../../images/bi_e_2_5_5.10.png)
- In the click action settings, the Discounted Price variable is selected. (Example screenshot 9 ../../images/bi_e_2_5_5.11.png)
- The Discounted Price variable updates using the formula
"product"."Unit Price" * (1 - "inputs"."Discount"/100). (Example screenshot 4 ../../images/bi_e_2_5_5.6.png) - To trigger the click action immediately upon clicking a product price, table filtering is disabled. (Example screenshot 7 ../../images/bi_e_2_5_5.9.png)
- Configuration is complete. Publish the dashboard. Set an arbitrary discount size, for example, 25%, and click any product price to execute the click action. (Example screenshot 5 ../../images/bi_e_2_5_5.7.png)
- The Discounted Price variable updates. (Example screenshot 6 ../../images/bi_e_2_5_5.8.png) -->
Click Action in YAML
To add a click action (UPDATE_VARIABLE), use the keys listed in the table. Specify these keys within the onClick block. Keys for the onClick block are described on the page Click Actions.
| Key | Type | Definition |
|---|---|---|
| variables | — | List of variables |
| name | string | Variable name |
| inputMethod | enum | Input Method |
Use the name and inputMethod keys inside the variables block. Example:
onClick:
- type: UPDATE_VARIABLE
name: Update Variable
variables:
- inputMethod: FORMULA
formula: '"product"."Unit Price" * (1 - "inputs"."Discount"/100)'
name: Discounted Price
Was the article helpful?
Yes
No