How to use a JIRA custom listener to copy comments from the parent issue to all sub tasks?
You can copy the comment added in the parent issue to all the associated sub tasks using the JIRA custom listener and grovvy script. All you need to do is to setup the custom listener and add the below grovvy script, which will take care of copying the comment to the sub task.
Groovy script:
// Namespaces
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor;
// Get the current issue
def issue = event.issue as Issue;
// Comment manager and the ticket user.
def commentManager = ComponentAccessor.getCommentManager();
ApplicationUser currentUser = event.getUser();
// Check the current issue is not the sub task.
if(!issue.isSubTask()){
// Get the parent issue's current comment
def comment = event.getComment();
// Loop through all the sub task associated with the parent issue
issue.getSubTaskObjects().each { it ->
Issue subtaskIssue = (Issue)it;
// Check the comment is already copied from the parent issue to the current sub task.
def childComment = commentManager.getComments(subtaskIssue).find{c -> c.body.equals(comment.getBody())};
if(childComment != null){
return;
}
// Create comment to the sub task from the parent issue.
commentManager.create(subtaskIssue, currentUser, comment.getBody(), true);
}
}
Leave a comment