Subtasks
This workflow automatically sets the state of a parent task when the state changes in issues that are linked as subtasks.
File Name | jetbrains-youtrack-subtasks |
---|---|
Auto-attached | yes |
Rules | Open parent task on any subtask open (stateless) Fix parent task when all subtasks are resolved (stateless) |
Use Case
You want to automatically update the state of a parent task when changes are applied to subtasks.
- When any subtask is set to an unresolved state, the state of the parent task changes to Open.
- When all subtasks are set to a resolved state, the state of the parent task changes to Fixed.
Rules
This workflow includes two rules.
Open parent task on any subtask open
When the state of an issue is set to an unresolved state, this rule checks whether the issue is linked as a subtask of a parent task. If the parent task belongs to an active project and has a resolved state, the state of the parent task is changed to Open.
rule Open parent task on any subtask open
when State != null && !State.isResolved && (State.oldValue != null && State.oldValue.isResolved) && subtask of.isNotEmpty {
var parent = subtask of.first;
if (parent != null && !(parent.project.isArchived()) && parent.isResolved()) {
parent.State = {Open};
if (parent.Type != null) {
message(l10n ( Automatically reopen {parent.Type} {parent.getId()} ));
} else {
message(l10n ( Automatically reopen {parent.getId()} ));
}
}
}
Fix parent task when all subtasks are resolved
When the state of an issue is set to a resolved state, this rule checks whether the issue is linked as a subtask of a parent task. If the parent task is unresolved, the rule checks the current state for all other issues that are linked to the parent task as subtasks. If all other subtasks are resolved, the state of the parent task is set to Fixed.
The rule then checks the parent task to see if it is linked as a subtask to a parent task and performs the same operation.
rule Fix parent task when all subtasks are resolved
when issue.isReported() && issue.becomesResolved() && issue.subtask of.isNotEmpty {
var parent = issue.subtask of.first;
while (parent != null && !parent.isResolved()) {
var allSubtasksResolved = true;
for each subtask in parent.parent for {
//We can't use subtask.isResolved() here, as this method relies on issue.resolved
//property, which is updated after workflow rules are executed.
if (!subtask.State.isResolved) {
allSubtasksResolved = false;
break;
}
}
if (allSubtasksResolved) {
parent.State = {Fixed};
message(l10n ( Automatically set {parent.getId()} as Fixed ));
}
//NPE-safe operation: if we can, we take the next ancestor and try to close it too
parent = parent.subtask of.first;
}
}