Workflow - Multiple assignees : Parent with multiple subtasks

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'
    }
  }
});

4 comments
Comment actions Permalink
Hi!

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.
0
Comment actions Permalink

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);    

class jetbrains.youtrack.scripts.wrappers.MutableIterableWrapper$ChangedIterable cannot be cast to class jetbrains.exodus.entitystore.Entity (jetbrains.youtrack.scripts.wrappers.MutableIterableWrapper$ChangedIterable and jetbrains.exodus.entitystore.Entity are in unnamed module of loader org.eclipse.jetty.webapp.WebAppClassLoader @89c5620)
 
            jetbrains.youtrack.scripts.wrappers.MutableIterableWrapper.doAdd(MutableIterableWrapper.kt:86)
0
Comment actions Permalink
Hello,

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);});
}
}
0
Comment actions Permalink

Hi,

Thanks so much! yes it works.

0

Please sign in to leave a comment.