Introduction
- Order Variables can be used to parameterize workflows and jobs.
- Order Variables are declared with a Workflow.
Feature Video
This video explains how to parameterize workflows and pass variables to jobs in a workflow.
Declaring Variables
Download example (upload .json): pdwVariablesDeclared.workflow.json
The JS7 - Workflow Editor allows variables to be declared. Clicking in the workflow editor panel will display the workflow properties where variables can be added:
Explanation:
- Order variables are declared by specifying a name and data type.
- If no default value is added then the order variable is mandatory, i.e. an order has to specify a value for the variable.
- If a default value is added then
- the order variable is optional, i.e. orders can specify a value and otherwise the default value will be used.
- the final data type can be used that prevents the variable from being modified after the point in time of submission of an order.
- Default values accept constant values and JS7 - Expressions for Variables.
- Any number of order variables can be declared.
For order variables of data type "String" the workflow editor offers the following operations from the icons:
- The icon invokes facet entry mode.
- The icon invokes the list entry mode.
- The icon invokes the editor entry mode for values of variables
Editor Entry Mode
Clicking the icon brings up a popup window that offers more space for character input to values of variables:
The window size will adjust automatically if more characters are entered.
- The icon can be used to maximize the window size.
- The icon can be used to change the window length.
List Entry Mode
The icon invokes the list editor that is used to compile a list of values which a user can select from when adding an order to the workflow.
In the Workflows view when an order is added users select from the list of values like this:
Facet Entry Mode
The icon invokes the facet editor. Facets are regular expressions that are used to check user input to match a given pattern.
Regular expressions can be complex and lengthy. The facet editor offers the Add from Favorites link to select values from JS7 - Inventory Favorites.
In the Workflows view when an order is added user input is checked like this:
- Input that does not match the regular expression is denied and the order cannot be submitted.
- An information icon displays a tooltip with the message that has been added to the facet.
Using Order Variables
Order variables can be used in a number of places:
- to populate environment variables that are used in shell jobs,
- to populate node arguments,
- to be evaluated by an expression in a JS7 - If Instruction.
Using Order Variables in Shell Jobs
Shell jobs can use environment variables to access order variables.
Mapping Order Variables to Environment Variables
A mapping is performed with the "Environment Variables" sub-tab of the job property editor:
Explanation:
- The property editor suggests using the names of order variables for environment variables.
- Environment variable names are created with the given spelling. In Unix environment variables are case-sensitive, in Windows they are case-insensitive.
- Similarly the values of order variables are suggested with a $ prefixing the name of the variable.
- Note that only names of existing order variables can be used as the value for an environment variable.
- In addition, expressions can be used for order variables - for details see:
Using Environment Variables in Job Scripts
Environment variables can be used in job scripts according to the syntax of the operating system that the job is executed for:
- for Windows use:
%VAR_STRING%
- For Unix use
$VAR_STRING
${VAR_STRING}
Using Node Arguments
Node Arguments are typically used in a situation when the same job occurs more than once in a workflow. The basic assumption is that the job will make use of the same variables which should carry different values at each node in which the job is used.
- Note that node arguments cannot be modified dynamically - which is why they are called arguments, not variables.
- Node arguments are available for mapping to environment variables in a similar manner to order variables.
Creating Order Variables
Order variables can be created dynamically from shell jobs.
- The job script can append a key/value pair to a temporary file indicated with the
JS7_RETURN_VALUES
environment variable. - The JS7 Agent will pick up the temporary file after execution of the shell job and will use the file's entries to create order variables for subsequent instructions and jobs in the workflow.
- This mechanism is used to create new order variables from Shell Jobs. It cannot be used to modify existing order variables declared with a workflow. Order variables that are not declared but created on-the-fly by shell jobs can be updated by subsequent shell jobs.
SOME_VARIABLE=some value echo "myVar=$SOME_VARIABLE" >> $JS7_RETURN_VALUES
set SOME_VARIABLE=some value echo myVar=%SOME_VARIABLE% >> %JS7_RETURN_VALUES%
Explanation:
- Both examples assign a value to an environment variable
SOME_VARIABLE
that is local to the job. - The key/value pair
myVar=....
is appended to the temporary file indicated by theJS7_RETURN_VALUES
environment variable.- This assignment makes use of the value stored in the
SOME_VARIABLE
environment variable. - This assignment could also use a constant value instead of using
SOME_VARIABLE
.
- This assignment makes use of the value stored in the
Built-in Variables
Built-in variables are available at the following scopes:
Workflow
$js7WorkflowPath
- The unique name of a workflow. Note that in a workflow the name does not include the folder location.
$js7WorkflowPosition
- The position of an order in the workflow.
$js7Label
- The label of the current instruction for which an order is executed.
$js7OrderId
- The order identifier.
$js7ControllerId
- The Controller's identifier as specified during installation.
Job
$js7JobName
- The name of the current job for which an order is executed.
$js7JobExecutionCount
- A counter for the number of times that the same job is executed for a given order, for example if an order is suspended and is resumed from an earlier job.
$js7EpochMilli
- The number of milliseconds since January 1st 1970 UTC.
$returnCode
- The numeric exit code of the current job for which an order is executed.
The following variables are available from later JS7 releases:
FEATURE AVAILABILITY STARTING FROM RELEASE 2.7.2
$js7MaxTries
- Indicates the maximum number of tries for a given order as configured with a JS7 - Retry Instruction.
- For an unlimited number of tries the variable returns the empty value.
- The variable is not defined outside of a Retry Instruction block.
$js7TryCount
- Indicates the current number of tries for a given order in a JS7 - Retry Instruction.
- The variable holds the 0 value when used outside of a Retry Instruction block.