Subtask Inherit Fix Versions
This workflow automatically updates the fix version of a subtask to the fix version set for a parent task.
Name | @jetbrains/youtrack-workflow-subtask-inherit-fix-versions |
---|---|
Auto-attached | yes |
Modules | Copy fix versions from parent task when issue is linked as a subtask (on-change rule) |
Use Case
This workflow helps you manage the fix version set for tasks and subtasks.
This workflow updates the values that are stored in the Fix versions custom field. To use this workflow, you need to make sure this field is used in the projects that you want to update. The option to store multiple values in the Fix versions field must be enabled in all of the projects that use this workflow.
Modules
This workflow includes the modules. The first two modules contain on-change rules that synchronize the value set for the Fix verions field between parent tasks and subtasks. The third module contains a custom script that is shared by these rules.
Copy fix versions from parent task when issue is linked as a subtask
This rule checks a subtask when it is linked to a parent task.
If the subtask belongs to a different project from the parent task and the projects use different sets of values for the Fix versions field, the fix versions are set for the parent task only.
If the subtask and parent task belong to the same project, the fix versions assigned to the parent task are set as the fix versions for any unresolved subtasks.
var entities = require('@jetbrains/youtrack-scripting-api/entities');
var workflow = require('@jetbrains/youtrack-scripting-api/workflow');
var copy = require('./copy-values');
exports.rule = entities.Issue.onChange({
title: workflow.i18n('Copy fix versions from parent task when issue is linked as a subtask'),
guard: function(ctx) {
return !ctx.issue.links['parent for'].added.isEmpty();
},
action: function(ctx) {
var issue = ctx.issue;
var safeSetFixVersions = function(subtask) {
if (subtask.project && !subtask.project.isArchived) {
if (subtask.project.key === issue.project.key || subtask.project.findFieldByName(ctx.FixVersions.name)) {
if (!subtask.isResolved) {
copy.copyValues(issue.fields.FixVersions, subtask, ctx.FixVersions);
}
}
}
};
issue.links['parent for'].added.forEach(safeSetFixVersions);
},
requirements: {
FixVersions: {
type: entities.ProjectVersion.fieldType,
name: 'Fix versions',
multi: true
}
}
});
Set fix versions for subtasks when fix versions are added to parent task
The next rule checks for subtasks when the fix versions are set for an issue.
If the subtasks are in an archived project or belong to a different project from the parent issue and the projects use different sets of values for the Fix versions field, the fix versions are set for the parent task only.
If the subtasks are in an active project and belong to the same project as the parent task, the fix versions for each unresolved subtask are set to the fix versions that are set for the parent task.
var entities = require('@jetbrains/youtrack-scripting-api/entities');
var workflow = require('@jetbrains/youtrack-scripting-api/workflow');
var copy = require('./copy-values');
exports.rule = entities.Issue.onChange({
title: workflow.i18n('Set fix versions for subtasks when fix versions are added to parent task'),
guard: function(ctx) {
return ctx.issue.fields.FixVersions.added.isNotEmpty();
},
action: function(ctx) {
var issue = ctx.issue;
var safeSetFixVersions = function(subtask) {
if (subtask.project && subtask.isReported && !subtask.project.isArchived) {
if (subtask.project.key === issue.project.key || subtask.project.findFieldByName(ctx.FixVersions.name)) {
if (!subtask.isResolved) {
copy.copyValues(issue.fields.FixVersions.added, subtask, ctx.FixVersions);
}
}
}
};
issue.links['parent for'].forEach(safeSetFixVersions);
},
requirements: {
FixVersions: {
type: entities.ProjectVersion.fieldType,
name: 'Fix versions',
multi: true
}
}
});
copy-values.js
This module contains a custom script that is used in both of the rules for this workflow.
exports.copyValues = function(values, to, field) {
field = to.project.findFieldByName(field.name);
if (field) {
to.fields[field.name].clear();
values.forEach(function(it) {
var version = field.findValueByName(it.name);
if (version) {
to.fields[field.name].add(version);
}
});
}
};