Skip to content

Variables

Variables are a method of storing static information that can be used within Workflows. For example you could have a Variable called "UserName" which contains the value "Paul". Variables are just "data" - they do not perform any function.

Variable Types

The following types of variables are available in Zynk, in order of precedence:-

System Variables

System variables include things such as the current date, time, year, etc. You cannot create your own or edit existing system variables, they are provided by Zynk. The table below shows the system variables that are available in Zynk.

Name Example
Guid 086a94c3-50b1-4ebc-8f21-de2570e57dbb
CurrentDate 14/02/2011
CurrentDateTime 14/02/2011 14:30:22
CurrentDay 14
CurrentMonth February
CurrentYear 2011
CurrentDayName Monday
CurrentLongDate Monday, 14 February, 2011

Global Variables

Global variables are defined within the main Zynk application and are accessible by all workflows and tasks. They should be used when data needs to be stored and shared between multiple workflows, an example would be the email address which Zynk should send all email notifications to. You can edit the Global variables using the 'Global Variables' button on the main toolbar, see Variable Collection Editor for more information.

Workflow Variables

Workflow variables are defined at the Workflow level and are accessible by all tasks within that Workflow including sub-tasks. They should be used when data needs to be stored and shared between the tasks in one workflow, examples would be a username and password or the path to a directory. You can edit the Workflow variables from the Properties tab, see Variable Collection Editor for more information.

Template Variables

Template variables are defined within the Razor Template task and are accessible from the template file. They can be used to pass information into the template at run time, such as a customer name or email address.

Current Variables

Current variables are only available within Repeater Tasks and represent the current row of data being processed in a data set. For example, if you are using the Excel Repeater to loop through each row in an Excel spreadsheet, each row would be converted to a collection of Current variables to be used by the repeater's sub tasks e.g. "Name", "Address", "Telephone" could be the variables available. Current variables cannot be created or edited directly by the user.

Configuring Variables

Only the editable variable types (global and workflow) can be configured by the user. Where to go to configure them depends on the type of variable.

Configuring Global Variables

Click the 'Global Variables' button in the main Zynk toolbar. This will display the Variable Collection Editor.

Configuring Workflow Variables

In the Workflow editor pane, click the Properties tab, then click on the ellipsis button next to the Variables property. This will display the Variable Collection Editor.

Workflow Variables

Variable Collection Editor

Global and Workflow variables are configured within the Variable Collection Editor, as shown in the screenshot below.

Variable Editor

A list of existing variables and their values is displayed in the 'Members' list on the left. New variables can be created using the 'Add' button. Existing variables can be copied using the 'Duplicate' button, or deleted using the 'Remove' button.

The following settings are available for each variable, on the right hand side of the window:

  • Encrypt - Set to True if you want Zynk to store the value of this variable in an encrypted form.
  • Key - Enter a name for the variable.
  • Required - Set to True if a value is mandatory for this variable. When this is enabled and no value is specified, any attempt to access the variable will cause the workflow to fail.
  • Value - Enter a value for the variable. The value is a Zynk Object, so it can store both static and dynamic values.

Using Variables

Variables can be used as the value for any task setting which accepts a Zynk Objects. Variables can also be accessed in templates. How to access the variable depends on the type of the variable.

Accessing System, Global and Workflow Variables

The simplest way to use system, global and workflow variables as the value for a task setting is to:

  1. Click on the '...' button at the edge of the task setting field.
  2. Select 'Variable' from the Data Type drop down menu.
  3. Select the variable you would like to use from the list.
    1. System variables are listed under the -- System Variables -- section
    2. Global variables are listed under the -- Application Variables -- section
    3. Workflow variables are listed under the -- Workflow Variables -- section

Zynk Object Editor - Variables

System and global variables can be accessed by any task in any workflow. Whereas workflow variables can only be accessed by the tasks in the workflow they belong to.

Accessing Any Variable Type With Razor

Razor can be used to access any type of variable in Zynk (except for system variables), and it's value can be used for a task setting or in a template. To use a variable for a task setting, you must enable the 'Use Razor Engine' option in the Zynk Object Editor. To access a variable with razor, reference the system Context and then choose the correct collection within that context, depending on the type of the variable.

Types of Variables and how to access them:-

Type Description Example
Application A setting contained in the Global Variables collection in Zynk @Context.Application["EmailAddress"]
Workflow A setting contained in the Workflow Variables collection @Context.Workflow["ServerPath"]
Template A setting contained in the Template Variables collection @Context.Template["CompanyName"]
Current A value from the current record in a Repeater task     @Context.Current["id"]                   
Object Access to the current record in a Repeater task  @Context.Object.SelectSingleNode("Name").InnerText (Assuming an XML Repeater Task)

The Zynk text editor has intellisense, to help you with accessing other variable types with razor.

Context Object for Repeater Tasks

A context object will contain a .NET object representing the current record within a repeater task. The type of the object will depend on the repeater task being used, the following table describes the different supported repeater tasks:

Task Object Type Example Documentation
File Repeater System.IO.FileInfo @Context.Object.FullName MSDN Documentation
XML Repeater System.Xml.XmlNode @Context.Object.SelectSingleNode("Name").InnerText MSDN Documentation
Excel Repeater  System.Data.DataRow  @Context.Object[0].ToString() MSDN Documentation
CSV Repeater System.Data.DataRow @Context.Object[0].ToString() MSDN Documentation
 ODBC Repeater System.Data.DataRow @Context.Object["NAME"].ToString() MSDN Documentation
OleDB Repeater System.Data.DataRow @Context.Object[0].ToString() MSDN Documentation
MSSQL Repeater System.Data.DataRow @Context.Object[0].ToString() MSDN Documentation

Example

In this example the current variables from a CSV Repeater task are used to dynamically set the output filename on a sub-task, based on the order numbers in this CSV file:

OrderNumber,CustomerId,Total
1250,32343,25.90
1251,74322,129.99
1252,87036,42.50

In the Zynk Object Editor for the output file setting on the sub-task, select the 'Use the following file' option and enter @(Context.Current["OrderNumber"]).csv in the box below. Remember to also select the 'Use Razor Engine' option. This will result in the sub-task creating the following output files in the workflow's data directory: 1250.csv, 1251.csv, 1252.csv.

Please note that if you are using a period in the file name, you must encase the Razor variable in brackets eg. @(Context.Current["OrderNumber"]).csv

Command Line Arguments

Any command line arguments that are passed to Zynk on start-up are automatically stored in global variables. This feature can be used to help integrate Zynk with other applications.

The variable keys will be named "Command Line ", followed by the zero based index of the argument. For example, if you start Zynk with the following command:

Zynk.exe "/r" "C:\ProgramData\Zynk Software\Zynk\3.0\Workflows\Global.wkf" "import.xml"

The following global variables will be created automatically:

Key Value
Command Line 0 /r
Command Line 1 C:\ProgramData\Zynk Software\Zynk\3.0\Workflows\Global.wkf
Command Line 2 import.xml

To use within Zynk, you could set the Input File of a task to use the following (with Razor enabled), which at runtime would be the file passed as the third argument to Zynk: -

@Context.Application["Command Line 2"]