Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Copy Comment from Child to Parent



I am trying to use listeners in Script Runner. When a comment is added in child/subtask it should automatically add that comment in Parent Task.

Below is Script:-



import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import org.apache.log4j.Category

class SubtaskCommentListener extends AbstractIssueEventListener {
Category log = Category.getInstance(SubtaskCommentListener.class)
CommentManager commentManager = ComponentAccessor.getCommentManager()

void workflowEvent(IssueEvent event) {
// only one central way...

void customEvent(IssueEvent event) {
// set explicit to debug
log.debug "Event: \"${ComponentAccessor.eventTypeManager.eventTypesMap[event.getEventTypeId()].name}\" fired for ${event.issue}"

// Here you should put any subtask based restrictions for this task like
// only for special subtask issue types or similar

Comment comment = event?.getComment()
if (comment && event.issue.isSubTask()) {
log.debug "New commment for subtask found."
Issue parent = event.issue.getParentObject()
// Here you should put any parent task based restrictions like
// only for special issue types or similar
commentManager.create(parent, comment.getAuthorApplicationUser(), comment.getUpdateAuthorApplicationUser(), comment.body, comment.groupLevel, comment.roleLevelId, comment.created, comment.updated, true, true)
log.debug ("Created comment on ${parent.key}")



The script is good but it is not working and jira version is 7.13

1 answer

0 votes
Manoj Kumar
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 03, 2023

You can try below 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();

// Determine whether the current issue is a subtask.

    // Get the subtask's current comment
    def comment = event.getComment();
    // Get the parent issue associated with the subtask
    issue.getParentObject().each { it ->
      Issue sourceIssue = (Issue)it;        
      // Determine whether the comment has already been added in the parent issue.
      def parentComment = commentManager.getComments(sourceIssue).find{c -> c.body.equals(comment.getBody())};
      if(parentComment != null){
      // Add a comment to the parent task from the subtask commen
      commentManager.create(sourceIssue, currentUser, comment.getBody(), true);

Suggest an answer

Log in or Sign up to answer