Use variables in automations
Overview
Data Management automations make extensive use of variables to transfer information produced by one step and consumed by a later step.
Automation variables
Automation-level variables are defined for the entire automation. All steps within the automation can access these variables.
To define automation variables:
Right-click the project window of an open automation, and then choose Automation Settings.
Select the Variables tab.
Select rows in the Automation variables grid and enter each Variable, its Type, and Initial value on a separate line.
![image-20240326-180845.png](../__attachments/3905454175/image-20240326-180845.png?inst-v=c3007bf4-8f91-43d3-9633-90859273c945)
Steps that produce or consume variable values let you add variables during configuration.
System variables
The following automation System variables are read-only. When used in an expression they must be prefaced with the system prefix.
Variable | Description | Type |
---|---|---|
| Time that the automation run started. |
|
| Date that the automation run started. |
|
| Date-and-time that the automation run started. |
|
| User running the automation. |
|
| Data Management version string, for example |
|
| Name of the automation being run. |
|
| Full path to the automation. |
|
| Directory containing the automation being run. |
|
| Hostname of the Execution Server. |
|
| Last-issued error message. |
|
| Name of the step that last issued an error message. |
|
| Date-and-time when the last error was issued. |
|
| Number of CPU cores enabled on the Execution Server. |
|
| Operating system process ID of the project or automation. Used to create uniquely-named files and tables, using the |
|
| Execution Server operating system. |
|
Add variables during configuration
Many steps let you define a variable as a part of the configuration. For example, the ForEach step can be configured to loop over a series of files and put the name of each file in a variable.
To create and use a variable in one step:
Select New from the list of available variables.
![](../__attachments/3905454175/att_8_for_3905454175.png?inst-v=c3007bf4-8f91-43d3-9633-90859273c945)
Specify the Name, data Type, and Default value of the new variable.
![](../__attachments/3905454175/att_7_for_3905454175.png?inst-v=c3007bf4-8f91-43d3-9633-90859273c945)
Use variables in expressions
Both the Branch and Expression steps accept expressions as part of their configurations. Branch uses expressions to determine which branch to signal. Expression uses expressions to set the values of variables.
For example, suppose a ForEach group is looping over files, and is configured to put the current file in the FILENAME
variable.
![image-20240326-181246.png](../__attachments/3905454175/image-20240326-181246.png?inst-v=c3007bf4-8f91-43d3-9633-90859273c945)
You can insert an Expression step into that group and configure it to build a new file name.
![image-20240326-181315.png](../__attachments/3905454175/image-20240326-181315.png?inst-v=c3007bf4-8f91-43d3-9633-90859273c945)
Expression replacement
You can use automation variables in the configuration of any step setting that accepts text, using the syntax ${expression}
. At execution time, ${expression}
is replaced with the result of evaluating that expression. The expressions can be simple variables like ${FILENAME}
. Or they can be more complex, calling functions like ${FileFromPath(FILENAME)}
. When concatenating strings in this way, use inline syntax and no " + " operator like ${TARGET_DIRECTORY}/${FileFromPath(FILENAME)}
.
Example:
The FileSystem step can move a file from one directory to another:
![image-20240326-181835.png](../__attachments/3905454175/image-20240326-181835.png?inst-v=c3007bf4-8f91-43d3-9633-90859273c945)
Suppose that you want to put the FileSystem step in a ForEach group that is looping over multiple files, and is configured to put the current file in the FILENAME
variable:
![image-20240326-181902.png](../__attachments/3905454175/image-20240326-181902.png?inst-v=c3007bf4-8f91-43d3-9633-90859273c945)
Within the group, you want to move each file found to the target directory. You must also extract the file name from its full path. If you configure the FileSystem step's File pattern setting with the expression ${FileFromPath(FILENAME)}
, you can use it in the ForEach loop:
![image-20240326-181950.png](../__attachments/3905454175/image-20240326-181950.png?inst-v=c3007bf4-8f91-43d3-9633-90859273c945)
Every time the ForEach loop finds a file, such as c:/temp/move_files_from/somefile.csv
, it reaches into the FileSystem step and replaces the ${FileFromPath(FILENAME)}
with the results of evaluating that expression, which in this case is somefile.csv
.