Work With Variables

You can define and use variables in your project as values that configure the processes and mappings behavior.

Understand Variables

There are three main types variables:

  • Metadata Variables: These variables are defined in Variable Set metadata in the project. You can modify these variables as the process runs, store and refresh their value from a database storage.

  • Substitution Variables that expose environmental information, such as the Designer or workspace folder.

  • Session Variables that expose variables available at runtime in sessions.

Metadata Variables

Metadata variables are used in projects to parameterize metadata, mappings, and processes. They are declared as project metadata and support storage and retrieval from database storage.

The specific Variable Manager action allows managing the metadata variables in processes.

Create a Variable Set

Variables are created in metadata having the Variable Set type. You must create a variable set metadata before defining variables.

To create a new variable set:

  1. Click the metadata New Metadata button in the Project Explorer toolbar. The New Model wizard opens.

  2. Select the Variable Set type.
    md variable

  3. Select a folder to store the metadata, and name the variable set with the Metadata Model Name.

  4. Click Finish.
    The variable set is created and the corresponding metadata editor opens.

  5. In the Standard section of the set editor, set the variable set Name. The default variable set name is Set You can optionally rename the set.

  6. Press Ctrl+S to save the variable set.

Create Variables

To add a variable to a variable set:

  1. In the variable set metadata editor, right-click the Set node and select New > Variable.
    The new variable is added to the set.

  2. In the Standard section of the set editor, set the base variable properties:

    • Enter the Name of the variable. Make sure to use a naming convention for your variables.

    • Select a Type for the Variable: String (default), Integer, Boolean or Float.

    • Enter a Default Value for the variable. If this value is defined as an expression, select the XPath Expression option.

  3. To store and refresh the variable from a database connection, set the following properties.

    • Refresh Query: Used if a Refresh Connection is defined. This query will be executed to retrieve a value for the Variable. In case of a query returning multiple rows or multiple columns (or both), the first column of the first row is used as the value

  4. Press Ctrl+S to save the variable set.

Configure Variable Storage

You can retrieve or persist variable values in a storage location, for example, in a table in a database server.

This storage for variables is configured as Connections in the variable set metadata. You can link database metadata to connections:

  1. Refresh variable values using a SQL query against the database.

  2. Persist and retrieve variable values from a table stored in the database.

Create Connections

To create a connection:

  1. In the variable set metadata editor, right-click the Set node and select New > Connection.
    The connection is added to the set.

  2. In the Standard section of the set editor, set a Name for the connection.

  3. In the Project Explorer, expand the metadata to show the artifact that will store the variable (for example, a database server)

  4. Drag and drop that artifact from the Project Explorer view to the metadata editor, under the connection.
    A metadata link is created under the connection, named after the metadata artifact.

  5. Press Ctrl+S to save the variable set.

You can use different types of metadata artifacts in the connection. For example, a database server, a schema, a table, or even a column.
You can define multiple connections in the Variable Set.

Once the connections are created, you can configure the set and the variables to use these connections, to save or refresh variables.

Configure the Set

On the Set, in the Standard section of the editor, define a Default Saving Connection and a Default Refresh Connection. These are used by all variables by default.

Configure Variables

On each variable, you can also define connections the method used to refresh or store the variable.

To configure a variable for database storage:

  1. In the variable set metadata editor, expand the set and then click the variable.

  2. In the Standard section of the set editor, set the following properties to configure database storage:

    • Saving Connection: The connection used to save the variable values. If unset, the default saving connection configured for the set is used.

    • Refresh Connection: Connection used by the Refresh Query. If unset, the default refresh connection configured for the set is used.

    • Refresh Query: This query is executed to retrieve a value for the variable. If the query returns multiple rows or columns, the first column of the first row is used.

    • Default Operation: Operation used by default for this variable when invoking the Variable Manager.

  3. Press Ctrl+S to save the variable set.

Write the Refresh Query

You can use the metadata artifact added under the connection to help write the refresh query.

Since it is a metadata link, you can use XPath and metadata functions between curly brackets to access the properties of this artifact.

For example:

  • For a schema artifact, get the schema name using:

    { ./tech:physicalName() }
  • For a schema artifact, get the qualified name of a table using:

    { ./md:objectPath(.,'MYTABLE') }
  • For table artifact, get the table qualified name using:

    { ./tech:physicalPath() }

Use Metadata Variables

You can use metadata variables at multiple locations in Semarchy xDI, as explained in the following sections.

Use Variables in Mappings

To use a variable in a mapping:

  1. Open the mapping that you want to edit.

  2. In the Project Explorer expand the variable set metadata to see the variable that you want to use.

  3. Drag and drop the variable from the Project Explorer view to the Mapping editor.
    The variable is added to the mapping as a new source.

  4. Drag and drop the variable from the mapping editor diagram to the target column, join, or the filter into which you want to use the variable.
    In the Expression Editor, the variable is added with the following syntax, where VARIABLE_NAME is the name of the variable.

    %{VARIABLE_NAME}%
    To retrieve or set variable value and use it a Mapping, instantiate the variable in the process as explained below with a SetValue or RefreshValue operation, then add the mapping to the process.

Manage Variables in Processes

You can use the Variable Manager action in a process to instantiate, set, refresh or save a variable.

To use a variable in a process:

  1. Open the process that you want to edit.

  2. In the Project Explorer expand the variable set metadata to see the variable that you want to use.

  3. Drag and drop the variable from the Project Explorer view to the Process editor.
    This instantiates a Variable Manager action linked to that variable. The variable predefined properties are automatically set for this action when the process is generated.

  4. Modify this action’s parameters in the Properties view to perform a specific variable action (Var Operation property), such as:

    • SetValue: Sets the variable value.

    • SetDefaultValue: Sets the variable to its default value.

    • RefreshValue: Refreshes the value with the Refresh Query.

    • IncrementValue: Increments the variable value.

    • SaveCurrentValue: Persist the current value of the variable.

Use Variables in Expressions

To use a variable in an expression, for example in action text, code, or parameter, instantiate the variable in the process, and use the %{VARIABLE_NAME}% syntax, where VARIABLE_NAME is the name of the variable.

Use Variables in Variables

You can use a variable to configure another variable in a variable set.

If the two variables are defined in the same Variable Set metadata, use the variable with the %{VARIABLE_NAME}% syntax, where VARIABLE_NAME is the name of the variable. This syntax can be used in the refresh query or default value properties.

If the two variables are defined in different Variable Sets, you must link the two metadata:

  1. Open the destination variable set metadata (the one that will use the other variable).

  2. In the Project Explorer expand the variable set metadata to see the variable that you want to use.

  3. Drag and drop the variable from the Project Explorer to the set node in the destination metadata editor.

  4. Use the variable with the %{VARIABLE_NAME}% syntax, where VARIABLE_NAME is the name of the variable. This syntax can be used in the refresh query or default value properties.

Use Variables in Metadata

To use a variable in the properties of a Metadata (for example, to use Variable in a Table condition), you must link the two metadata:

  1. Open the destination metadata (the one that will use the variable).

  2. In the Project Explorer expand the variable set metadata to see the variable that you want to use.

  3. Drag and drop the variable from the Project Explorer to the destination metadata editor.

  4. Use the variable with the %{VARIABLE_NAME}% syntax in properties of the destination metadata, where VARIABLE_NAME is the name of the variable.

Substitution Variables

Substitution Variables expose environmental information, such as the Designer or workspace folder, and can be used in the expressions. These variable may be Semarchy xDI Designer predefined variables or your own.

  • Substitution Variables are local. They contain workspace information that may be useful in certain cases.

  • Substitution Variables are evaluated at generation-time, and when using the Metadata wizards.

  • Substitution Variables cannot be externalized. Their values are inserted as-is in generated delivery.

Use Substitution Variables in Expressions

You can use a String Substitution variable with the following syntax, where variable_name is the name of the variable:

%{env:variable_name}%

For example, to retrieve the project name:

Example 1. Retrieve the project name
%{env:project_name}%

The list below contains a subset of the available variables available by default in Semarchy xDI Designer.

You can define your own Substitution variable in the Semarchy xDI Designer preferences, in the String Substitution section.
Table 1. Predefined Substitution Variables
Variable Name Description

eclipse_home

Absolute path of the Designer installation folder.

workspace_loc

Absolute path of current workspace folder.

project_name

Name of the Project from which the value is generated.

project_loc

Absolute path of the Project from which the value is generated.

resource_name

Name of the resource from which the value is generated, which can be for instance the name of the Process in which the value is generated.

resource_loc

Absolute path of the resource from which the value is generated, which can be for instance the path of the Process in which the value is generated.