Variables are divided into two kinds: global and local. Local variables exist only within their business process during its execution. The values of global variables are stored in RAM and can be used in different BPs.
In AppMaster, you can create variables for the backend and frontend. The use of global variables allows to speed up the application and minimize the number of queries to the database.
Storage in RAM imposes some restrictions on the operation of global variables:
- When the application is restarted, the global variables will take on the default values.
- For web applications, each browser tab is a separate running instance. Accordingly, each copy will have its own values of global variables.
Global variables
To create a global backend variable, go to the Business Logic tab, select the Global Variable tab and click Create global variable.
Here you can:
- Select variable type;
- Give it a name;
- Specify a description;
- Turn on/off the Read only option.
When the Read only option is enabled, the variable's value cannot be changed in business processes.
When you select a variable type, you can set a default value.
When a global variable is created, it can be found in the Business Processes editor in the Global Variables tab.
Local variables
Here, local variables can also be created. They are located in the Variables section.
To create a local variable, you need to drag it onto the canvas. You can set the value of a variable using the Set variable block. To define which variable to store the value in, connect the variable to the Variable input field of the Set Variable block. The value parameter can be set by default or dynamically passed from another block.
The Set variable block can be used to set both a global and a local variable.
A local variable can only be used in the BP where it was created.
To create a global variable in the frontend, open the application in the editor. The instruction is similar for web and mobile applications.
Go to the Global Variables tab in the application editor and click Create global variable.
Creating a global variable for the frontend looks almost the same as the backend.
Only one additional field will be added – Persistent.
Enabling this option allows the value of the variable to be saved between application launches. To use a global frontend variable or add a local frontend variable, go to the Workflow tab of any element, for example, a table. As with the backend, you can use global variables and create new local ones.
When using the frontend variables, different triggers, although located on the same screen, launch separate independent BP. Below is an example:
An Integer is a local variable. The logic of work:
When the onShow trigger fires, the Set Variable block sets the value of the Integer variable. When the onClick trigger fires, the value from the Integer variable must go into the To String block and then into the Notification block.
Such logic will not work for a local variable since each trigger launches its own BP. Therefore, when triggered by the onClick trigger, the value of the local variable will not be set.
To fix this, use a global variable instead of a local one.