Lead your team forward
OCT 24 / 9AM ET Register nowExpressions in Workflows
It is possible to use ONE expression syntax, functions, and operators when configuring workflows. In addition to the ONE functions, there are also special Workflow Functions.
Where to use expressions?
You can use expressions when configuring task properties, links, and when defining derived variables.
In task properties
See the documentation of the specific task to find out which task properties support expressions. Look for the Expression support column.
The properties that support expressions have either "expression" or "semi-expression" specified, which defines the context in which the expression can be used in the given property.
In links
Expressions can be used when defining conditions on links, according to the rules of described in Expression context
In derived variables
Expressions can be used when defining derived variables, according to the rules of described in Expression context
Contexts
Generally, expressions occur in two contexts, which determines how they are written.
Expression context
Expression context is when an expression is expected explicitly, for example, a condition on a link.
In general, any configuration property whose name is Expression is in the expression context. |
Some general rules for the expression context:
-
Use expressions and variables as they are.
-
Enclose strings into double or single quotes.
Make sure the expression evaluates to an appropriate data type. |
Example 1
The following expression concatenates the string names_
with the result of the expression toString(today(),"YYYY-MM-d")
and another string .txt
and sends it to the ONE plan as a parameter.
Example 2
The following table shows how quotation marks affect an expression result:
Expression | Expression evaluates to |
---|---|
|
|
|
|
|
|
|
|
If we consider two sample expressions, a sum 2+3
, and an expression using an input variable filevar
with a value tuesday.csv
, then depending on the quotation mark used, they evaluate as follows:
Expression 1 | Expression 2 |
---|---|
|
|
|
|
|
"'" + filevar + "'" evaluates to |
|
"'" + 'filevar' + "'" evaluates to |
Semi-expression context
Semi-expression context typically occurs in string attributes of the task configuration properties. These properties are marked with "semi-expression" in the task documentation. See the Workflow Tasks section in the documentation.
When in the semi-expression context, you must prefix expression blocks with a dollar sign ($
) and place them between curly brackets ({}
) so that the workflow engine can distinguish expressions from the common string.
The following example shows an expression used to retrieve the current date and time and present them in a derived format when reporting success in the Run Windows Command task.
Escaping
Expressions and semi-expressions use same escaping character—a backslash (\
)--across the whole expression or semi-expression definition.
As a resullt, you must double the backslash if you want to use it in its literal meaning, which is usually when specifying paths in the Windows OS context.
We strongly recommend using a forward slash (/ ) in all filesystem paths (except in Run Windows Command, where it is not allowed) to avoid having to escape the backslash.
|
Escape the backslash
Here are several examples to help you understand where the backlash should or should not be escaped.
Example 1: Run Windows Command task
In the Run Windows Command task, the correct way to write a copy command is copy c:\\temp\\some-file.txt d:\\temp
, which the workflow engine evaluates to copy c:\temp\some-file.txt d:\temp
.
Example 2: Operate on File task
In the Operate On File task, the correct way to specify the target file is d:\\temp
, which the engine evaluates to d:\temp
.
Example 3: Derived variable
When specifying a Windows OS path in a derived variable, escape the backslash.
Example 4: Input variables
You do not need to escape the backslash when passing a path in an input variable: the Workflow engine treats it as a literal string.
For example:
-
Assume that
gloVar=c:\temp\file.txt
. -
Assume the following definition in the Run Windows Commandtask:
copy ${gloVar} d:\\temp
. -
The result of command processing would be:
copy c:\temp\file.txt d:\temp
.
Escape the double quotes in scripting tasks
The following is an example of escaping double quotes ("
) in the Run Windows Command and Run Shell Script tasks.
Assume that global_variable=2
.
Expression | Windows OS | Unix-like |
---|---|---|
|
|
|
|
|
|
The rule for batch and shell scripts is that the double quotes are a special character indicating the beginning and ending of a string, with everything in between treated literally. Therefore, you must escape the double quotes if you need to use a variable or expression between them.
Escaped characters
The following table summarizes the characters that you must escape if you want to use them in their usual meaning given the context.
Character to escape | Context | Usual meaning in the context | Example |
---|---|---|---|
Single ( |
expression |
Beginning of a string |
Condition on a link: |
Backslash ( |
semi-expression or expression |
Path separator on Windows |
Run Windows Command: |
Dollar sign and open curly bracket ( |
semi-expression |
Beginning of an expression |
Run Windows Command: |
Was this page useful?