Workflow - Multiple assignees : Parent with multiple subtasks Follow
Hi,
I am struggling to solve the following issue: We have parent tasks that contains one or more subtasks. When we update the subtask Assignees we want the parent task to be updated with the Assignee. So a parent will have all the assignees that exist in all the subtasks.
Currently the Assignment operator overwrites the any existing Assignees in the parent instead of adding or removing:
const entities = require('@jetbrains/youtrack-scripting-api/entities');
exports.rule = entities.Issue.onChange({
title: 'Update assignee in parent when subtask is assigned',
guard: (ctx) => {
return ctx.issue.fields.isChanged(ctx.Assignee);
},
action: (ctx) => {
const issue = ctx.issue;
const safeSetAssignee = function (parent) {
parent.links['parent for'].forEach(function(child) {
if (child.project && !child.project.isArchived) {
if (child.fields.Assignee.isChanged) {
parent.fields.Assignee=child.fields.Assignee; //Here I would like to add
}
}
});
};
issue.links["subtask of"].forEach(safeSetAssignee); //get each subtask
},
requirements: {
Assignee: {
type: entities.User.fieldType,
multi:true
},
Subtask: {
type: entities.IssueLinkPrototype,
name: 'Subtask',
outward: 'parent for',
inward: 'subtask of'
}
}
});
Please sign in to leave a comment.
You need to use the `.add` method, like the following: `issue.fields.Assignee.add(ctx.currentUser);`. It will add a user to the field if this user is not there yet.
Hi,
Thanks for the feedback - I dont want to assign the current user (the current user isnt necessarily the assignee) and if I try add the subtask.fields.Assignee to the parent if fails: parent.fields.Assignee.add(child.fields.Assignee);
Please use the following code:
if (child.project && !child.project.isArchived) {
if (child.fields.Assignees.isChanged) {
child.fields.Assignees.forEach(function(assign){
parent.fields.Assignees.add(assign);});
}
}
Hi,
Thanks so much! yes it works.