# How to Work with Variables

Variables are the user defined fields that:

* can have any desirable name
* can have value of String type
* can be inserted anywhere as [Merge field](https://docs.flexikanban.ai/standard-kanban/tools/using-merge-field-picker)
* can be updated by [Actions](https://docs.flexikanban.ai/components/actions-action-groups)
* are initialized with initial values when Kanban page is loaded or reloaded
* are stored in memory and do not changed when Kanban is refreshed by Kanban API or "Refresh Kanban" button (and this is a perfect tool to dynamically change a lot of Kanban properties)

Variables are configured in the [proper section](https://docs.flexikanban.ai/standard-kanban/configure-kanban/how-to-configure-variables) of Kanban Properties sidebar.

To see what values are stored in the variables, and manipulate with them, user can open a [Debug Console](https://docs.flexikanban.ai/standard-kanban/using-kanban/how-to-debug-a-kanban) on Kanban.

Variables can be changed by different actions:

* "Update Variables" method of  [Kanban API](https://docs.flexikanban.ai/components/actions-action-groups/types/kanban-api-action) - it allows the simple update of variable with some value.
* "Define Variable" [Global Action](https://docs.flexikanban.ai/components/actions-action-groups/types/define-variable-action) - it allows to make calculations with variable values using formulas.<br>

Define Variable Action called from Kanban has these properties:

* it always return updated variables to Kanban where it has been called from
* it need to know the name of variable to update<br>

Example of how to CHANGE variable value via Define Variable Action:

1\. Configure action in this way:

* Type = Define Variable
* Variable Type = JSON
* Variables JSON example:

```
{"{$Variables.IncomingVariableName}":"FORMULA[IF({$Variables.IncomingVariableValue} != '1','zero','one')]"}
```

This formula updates variable value to "one" if its initial value is "1", and to "zero" if not.

{% hint style="info" %}
In the example above name of variable to update is got from Action incoming variables (that work as parameters) using merge field {$Variables.IncomingVariableName}. Initial value of variable to update is set by {$Variables.IncomingVariableValue}.\
\
Thus, an action call can pass any Kanban variable to action as pre-defined variables named "IncomingVariableName" and "IncomingVariableValue". This will allow user to re-use this action anywhere with other variables.
{% endhint %}

2\. Define some variable on Kanban, e.g. variable name = "TheVar" and value = "A":

<figure><img src="https://3097383375-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FK2dgObBO5ydOH2ZXDJLa%2Fuploads%2FWsc9eMCvLPfbGeyzCYGK%2Fimage.png?alt=media&#x26;token=60762163-9986-4adb-959b-6f5fb4a189ff" alt=""><figcaption></figcaption></figure>

3\. Configure an action (e.g., as handler on some element) and pass this variable name and value to action via action incoming variables:

<figure><img src="https://3097383375-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FK2dgObBO5ydOH2ZXDJLa%2Fuploads%2FCuRZXjAls1Da2O6LDrum%2Fimage.png?alt=media&#x26;token=86050491-9dee-486b-bff0-5cbd57183d21" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3097383375-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FK2dgObBO5ydOH2ZXDJLa%2Fuploads%2FGQMYqUgSnShAmLekZVBf%2Fimage.png?alt=media&#x26;token=e5cf91ee-2eec-405b-89bf-bc52ba08e75e" alt=""><figcaption></figcaption></figure>

Save Kanban.\
To test variables update open Kanban and check variable in Debug Console. It will show initial variable value:

<figure><img src="https://3097383375-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FK2dgObBO5ydOH2ZXDJLa%2Fuploads%2FZsrjG7hmdTDdhVe1Ue6d%2Fimage.png?alt=media&#x26;token=3fa42210-7e33-4267-bde6-15dbecbe29bc" alt=""><figcaption></figcaption></figure>

Click on element with this action set as handler. Then open debug console again to see an updated variable:

<figure><img src="https://3097383375-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FK2dgObBO5ydOH2ZXDJLa%2Fuploads%2FCE1gYXayzyun9WmPem1T%2Fimage.png?alt=media&#x26;token=893a4614-f34b-4dfc-b9fa-36eb8451f639" alt=""><figcaption></figcaption></figure>

This way does not allow to update variable in other Kanban, but you can first update variable in current Kanban with global action, and then [pass new value to other Kanban](https://docs.flexikanban.ai/standard-kanban/howtos-and-best-practices/how-to-configure-communication-between-kanbans) via Kanban API "Update Variable" method.
