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:

  1. When the application is restarted, the global variables will take on the default values.
  2. 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.

How to create a variable

Here you can:

  1. Select variable type;
  2. Give it a name;
  3. Specify a description;
  4. Turn on/off the Read only option.

When the Read only option is enabled, the variable's value cannot be changed in business processes.

Setting up variable parameters

When you select a variable type, you can set a default value.

Default value for variable

When a global variable is created, it can be found in the Business Processes editor in the Global Variables tab.

Variable in BP

Local variables

Here, local variables can also be created. They are located in the Variables section.

Creating local variable

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.

How to set a variable value

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.

Persistent field

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.

How to use variables on frontend

When using the frontend variables, different triggers, although located on the same screen, launch separate independent BP. Below is an example:

Example usage of a variable in BP

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.

Was this article helpful?

AppMaster.io 101 Crash Course

10 modules
2 weeks

Not sure where to start? Get going with our crash course for beginners and explore AppMaster from A to Z.

Start Course
Development it’s so easy with AppMaster!

Need More Help?

Solve any issue with the help of our experts. Save time and focus on building your applications.

headphones

Contact Support

Tell us about your problem, and we’ll find you a solution.

message

Community Chat

Discuss questions with other users in our chat.

Join Community