Global variables
Global variables are a new feature that allows users to define a single variable that can be reused across multiple processes. For example, you have a connection string to an external database that is being used in multiple processes on several places. Right now you need to have a local variable in each of those processes. With global variables, you define a single variable that each process can reuse, for some reason that variable changes, you do not need to update all of your processes, just the global variable and all your processes will run as expected.
Creating your first global variable
Go to Global variables tab
Click Create Variable
You will be presented with Create Variable screen
Here you are presented with several options:
- NAME: This name is UNIQUE per variable scope, meaning you can not have two variables of the same name with the same scope and stage area, so pick your name wisely.
- IS CONSTANT: If a variable is defined as constant, it cannot be changed within the process, only in the Global variables repository.
- TYPE: variable type: string/decimal/integer
- VALUE: the value of the variable that will be used in the process
- STAGE AREAS : Global variables allow you to have different values at different stages. If we take the example from introduction: During the development stage, you might be connecting to a local database. After completing the process and you are ready to test the process on the test environment, you will create a global variable with the same name but a different stage area (TEST) and a different value (value of the test database). After you are done testing, repeat the process for production, publish and you are all set!
- SCOPE LEVEL : Three scopes are available: Organization/Department/Process. Scope level defines a measure of restriction/segregation of global variables.
- ORGANIZATION: Definition for a variable that can be accessed by all processes within your organization.
- DEPARTMENT: Only processes that belong to a specific departments can see that global variable.
- PROCESS: Only the selected Processes can see and use that global variable.
- IS VISIBLE CHECKBOX: If you check this, then the value can be seen from your browser for the variable you chose. If left unchecked, once created global variable value can never be seen in the global variable display. This is done when global variables contain sensitive information, and we do not want them leaving the server other than for robot execution during runtime.
Using global variables in your processes
Say we have a global variable of type string that we want to use in our process in string step.
As you can see we have two types of variables now. The first one is the global variable( denoted by the blue dot next to it), other is the local variable defined within the process with the Define Variable step. Depending on which value you want to use, pick the appropriate variable. This means global variables and local variables of the same name can coexist in the same process.
Naming Global Variables
There are specific rules for naming variables, including keywords in C# and Python that are not allowed.
Start Character:
- The variable name must start with a letter (a-z or A-Z) or an underscore (_).
- It cannot start with a number or any other character.
Allowed Characters:
- The variable name can only contain letters, digits (0-9), and underscores (_).
- It cannot contain spaces, hyphens (-), special characters (like @, !, #, etc.), or punctuation.
Keyword Restriction:
- The name cannot be a reserved keyword in Python or C#.
- Using a keyword as a variable name would cause syntax errors or unexpected behavior.
- Disallowed: Reserved Keywords (these keywords cannot be used as variable names):
- Python keywords: False, None, True, and, as, assert, async, await, break, class, continue, def, del, elif, else, except, finally, for, from, global, if, import, in, is, lambda, nonlocal, not, or, pass, raise, return, try, while, with, yield
- C# keywords: abstract, base, bool, byte, case, catch, char, checked, const, decimal, default, delegate, do, double, enum, event, explicit, extern, fixed, float, foreach, goto, implicit, int, interface, internal, lock, long, namespace, new, null, object, operator, out, override, params, private, protected, public, readonly, ref, sbyte, sealed, short, sizeof, stackalloc, static, string, struct, switch, this, throw, typeof, uint, ulong, unchecked, unsafe, ushort, using, virtual, void, volatile
Global variables business rules, restrictions, and everything else
- Global variable name is unique. You cannot have two variables of the same Name and Scope Level across different stages.
- If using global variables in your process, make sure the global variable exists on the stage you are publishing to. For example, if you have a global variable on the development stage, you cannot publish to the test stage if a global variable with the same name does not exist on the test stage. If you try to publish to a stage where global variables do not exist you will get the following error :
- Global variable cannot be deleted if it is still used in different processes. This is done to prevent a user from corrupting their processes accidentally.
This rule will be revisited and will probably be changed in the near future.