Subtask Inherit Assignee
This workflow automatically sets the assignee of a subtask to the user who is assigned to work on the parent task.
Use Case
This workflow helps you manage the assignment of tasks and subtasks.
Modules
This workflow includes two modules.
Assign subtask to assignee of parent issue
This rule checks a subtask when it is linked to a parent task. If the subtask is not assigned, the issue is assigned to the assignee of the parent task.
var entities = require('@jetbrains/youtrack-scripting-api/entities');
var workflow = require('@jetbrains/youtrack-scripting-api/workflow');
exports.rule = entities.Issue.onChange({
title: workflow.i18n('Assign subtask to assignee of parent issue'),
guard: function(ctx) {
return !ctx.issue.links['parent for'].added.isEmpty();
},
action: function(ctx) {
var issue = ctx.issue;
var safeSetAssignee = function(subtask) {
if (subtask.project && !subtask.project.isArchived) {
if (subtask.project.key === issue.project.key || subtask.project.findFieldByName(ctx.Assignee.name)) {
if (!subtask.fields.Assignee) {
if (!issue.fields.Assignee ||
subtask.project.findFieldByName(ctx.Assignee.name).findValueByLogin(issue.fields.Assignee.login)) {
subtask.fields.Assignee = issue.fields.Assignee;
}
}
}
}
};
issue.links['parent for'].added.forEach(safeSetAssignee);
},
requirements: {
Assignee: {
type: entities.User.fieldType
},
Subtask: {
type: entities.IssueLinkPrototype,
name: 'Subtask',
outward: 'parent for',
inward: 'subtask of'
}
}
});
Update assignee for subtask when parent issue is reassigned
The next rule checks for subtasks when an issue is assigned to another user.
If the subtasks are in an active project, the assignee for each subtask is set to the assignee of the parent task.
If the subtasks are in an archived project, they are ignored.
var entities = require('@jetbrains/youtrack-scripting-api/entities');
var workflow = require('@jetbrains/youtrack-scripting-api/workflow');
exports.rule = entities.Issue.onChange({
title: workflow.i18n('Update assignee for subtask when parent issue is reassigned'),
guard: function(ctx) {
return ctx.issue.fields.isChanged(ctx.Assignee);
},
action: function(ctx) {
var issue = ctx.issue;
var safeSetAssignee = function(subtask) {
if (subtask.project && subtask.isReported && !subtask.project.isArchived) {
if (subtask.project.key === issue.project.key || subtask.project.findFieldByName(ctx.Assignee.name)) {
if ((issue.fields.oldValue(ctx.Assignee) || {}).login === (subtask.fields.Assignee || {}).login) {
if (!issue.fields.Assignee ||
subtask.project.findFieldByName(ctx.Assignee.name).findValueByLogin(issue.fields.Assignee.login)) {
subtask.fields.Assignee = issue.fields.Assignee;
}
}
}
}
};
if (issue.fields.isChanged(ctx.Assignee)) {
issue.links['parent for'].forEach(safeSetAssignee);
}
},
requirements: {
Assignee: {
type: entities.User.fieldType
},
Subtask: {
type: entities.IssueLinkPrototype,
name: 'Subtask',
outward: 'parent for',
inward: 'subtask of'
}
}
});
Last modified: 17 December 2019