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. 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, a list can be found in the Variables article.
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 Global Variables 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 Variables 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 Task Types 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.
Editing Variables
All editable variables are edited within a Variable Collection Editor. A list of existing variables and their values is displayed in the 'Members' list on the left. You can change the key (i.e. name) and value of the variables using the properties list on the right. New variables can be created using the 'Add', and existing variables can be deleted using the 'Remove' button.
Using Variables
See Accessing Variables in Tasks for information about how to use variables in your workflow's tasks..
Accessing Variables in Tasks
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
You can use system, global and workflow variables for task settings using the 'Use a variable from the list below' option on the Zynk Object Editor. Simply select the name of the variable from the list provided, and it's value will be used as the value for the setting.
Accessing Other Variable Types 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
Configure Workflow Variables
Workflow variables are configured in the same way as Global Variables, but can only be accessed at Task and Template level.
To access Workflow Variable editor, click on Workflow editor pane, choose Properties and click on the ellipsis button next to the Variables property.
Using Global Variables
Global variables can be accessed by any task in any workflow. This differs from workflow variables, which can only be accessed by the tasks in that workflow. 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.
Creating Global Variables
New global variables can be created by clicking the 'Global Variables' button in the main Zynk toolbar. You will then be presented with a window like the one below.
]
- Click the 'Add' button to add a new global variable.
- Enter a name for the variable in the 'Key' field.
- Enter a value for the variable in the 'Value' field. The value is a Zynk Object, so it can store both static and dynamic values.
- When you are finished adding global variables, click the OK button.
Accessing Global Variables
The value of a global variable can be used any task setting which accepts a Zynk Object. To use a variable for a task setting, click on the '...' button at the edge of the field. You will then see the following window.
- Select 'Variable' from the Data Type drop down menu.
- Select the variable you would like to use from the list. Global variables are listed under the '-- Application Variables --' section.
Command Line Arguments
Any command line arguments that are passed to Zynk are stored in global variables, prefixed with "Command Line ", followed with a zero based index of the argument. As an example, calling Zynk with the following: -
Zynk.exe "/r" "C:\ProgramData\Zynk Software\Zynk\2.0\My Workflows\Global.wkf" "import.xml"
Would store as: -
- Command Line 0 = /r
- Command Line 1 = C:\ProgramData\Zynk Software\Zynk\2.0\My 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"]
Using System Variables
The following system variables are available in Zynk.
- Guid e.g. 086a94c3-50b1-4ebc-8f21-de2570e57dbb
- CurrentDate e.g. 14/02/2011
- CurrentDateTime e.g. 14/02/2011 14:30:22
- CurrentDay e.g. 14
- CurrentMonth e.g. February
- CurrentYear e.g. 2011
- CurrentDayName e.g. Monday
- CurrentLongDate e.g. Monday, 14 February, 2011
Accessing System Variables
The value of a system variable can be used any task setting which accepts a Zynk Objects. To use a variable for a task setting, click on the '...' button at the edge of the field.
- Select 'Variable' from the Data Type drop down menu.
- Select the variable you would like to use from the list. System variables are listed under the
-- System Variables --
section.