Add global variable
Function: Add global variable
This action allows you to create a new global variable or update an existing one within your application. Global variables are powerful tools that store information accessible throughout your entire application, including on different pages or within other actions.
When you set a global variable, any placeholder on your page that matches the variable's name (e.g., \{\{FIRSTNAME\}\}
) will automatically update to display the variable's value. This is incredibly useful for personalizing content, storing user preferences, managing application-wide settings, or sharing data between different parts of your application without needing to pass it explicitly.
Input
- Variable name: (STRING, Required)
The unique name you want to give to your global variable. This name should be distinct across your entire application to avoid conflicts. For example,
UserName
,CurrentDate
,ProductPrice
. - Variable value: (VARIABLE, Required) The actual data or information you want to store in this global variable. This can be any type of data, such as text, a number, a true/false value, a date, or even more complex data structures.
Output
- Variable name: (STRING) The name of the global variable that was successfully added or updated.
Execution Flow
Real-Life Examples
Example 1: Personalizing a Welcome Message
Imagine you want to greet your users by their name after they log in.
- Inputs:
- Variable name:
LoggedInUserName
- Variable value:
Sarah
- Variable name:
- Result: A global variable named
LoggedInUserName
is created with the valueSarah
. Any text on your page like "Welcome,\{\{LoggedInUserName\}\}
!" will now automatically display as "Welcome, Sarah!". The action outputsLoggedInUserName
.
Example 2: Storing a User Preference
You might want to remember if a user prefers dark mode or light mode for your application.
- Inputs:
- Variable name:
DarkModeEnabled
- Variable value:
true
(a boolean value)
- Variable name:
- Result: A global variable named
DarkModeEnabled
is created with the valuetrue
. This variable can then be used by other parts of your application to dynamically switch the user interface to dark mode. The action outputsDarkModeEnabled
.
Example 3: Updating a Product Price
If you have a dynamic pricing system, you might need to update the displayed price of a product across multiple pages.
- Inputs:
- Variable name:
CurrentProductPrice
- Variable value:
129.99
(a number)
- Variable name:
- Result: A global variable named
CurrentProductPrice
is created with the value129.99
. This value can be displayed on product pages, in a shopping cart summary, or used in calculations throughout your application. The action outputsCurrentProductPrice
.
Example 4: Setting a Dynamic Date for Reports
You could use a global variable to store the current date, which can then be used in report headers or as part of a timestamp.
- Inputs:
- Variable name:
ReportDate
- Variable value:
2023-10-27
(a date value, or a string representing a date)
- Variable name:
- Result: A global variable named
ReportDate
is created with the value2023-10-27
. This can be used to display the current date in various parts of the application, such as "Report generated on\{\{ReportDate\}\}
". The action outputsReportDate
.