Statements
YouTrack workflow language supports several standard iterative and conditional statements. These statements function as expected as in other structured programming languages.
Statements by Type | ||
---|---|---|
The syntax for statements is similar to JavaScript.
- A single statement may span multiple lines.
- Each statement is separated by a semicolon.
- Multiple statements may occur on a single line if each statement is separated by a semicolon.
Block statements group one or more statements. The block is delimited by a pair of braces.
Control Flow
The following control flow statements are supported.
The following example from the default workflows illustrates how to use a control flow statement in a workflow.
var user;
if (issue.Assignee == null) {
user = issue.project.leader;
} else {
user = issue.Assignee;
}
In this example, the if
statement assigns an issue and sets the value of the user
variable to the project leader when the value for the Assignee field is not set.
If the issue has already been assigned to another user, the else
statement sets the value of the user
variable to the current assignee.
Iterations
The following statements can be used to iterate over a sequence of elements.
When you iterate over a collection with a for each
statement, you define an arbitrary variable that references the elements in the sequence in the statement itself.
The following examples from the default workflows illustrate how to use iterations in workflows.
var duplicatedBy = is duplicated by;
for each duplicate in duplicatedBy {
if (duplicate.project == project) {
duplicate.Fixed in build = Fixed in build;
}
}
In this example, the for each
statement checks the sequence of issues with the duplicatedBy
link type.
If the project property of any issue in the sequence matches the current project, the value of the Fixed in build is set.
The variable duplicatedBy
represents the sequence of issues that are linked to the current issue with the link name is duplicated by
.
Each issue in the sequence is assigned the variable name duplicate
.
for each duplicatedIssue in duplicates {
if (duplicatedIssue.project == project && duplicatedIssue.Fixed in build != null) {
Fixed in build = duplicatedIssue.Fixed in build;
break;
}
}
In this example, the for each
statement checks the sequence of issues with the duplicates
link type.
If the project property of any issue in the sequence matches the current project and the current value of the Fixed in build is not null
,
the value of the Fixed in build is set.
In this example, the sequence of issues that are linked to the current issue have the link name duplicates
.
Each issue ini the sequence is assigned the variable name duplicatedIssue
.
Warnings and Errors
The following statements display errors or warnings to the user and write messages to the log files in YouTrack.
debug(string) | |
---|---|
Parameters | string: The text to write to the log file. |
Description | Writes the specified string of text in the worklfow.log and youtrack.log files. |
Example | debug("The number: "+ number); |