Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Comments from Sub-Task to Parent

anthony_butler March 8, 2019

Hi, 

I'm wanting the comments made on a Sub-Task to appear on the parent ticket. I'd like this to happen for each comment that is made on the sub-tasks. 

 

I've heard tell that using a script in scriptrunner will do this and found this page     which seems to give some information but I'm getting errors when I put this into scriptrunner: Scriptrunner error.PNGI ignore this (rightly or wrongly) and save it, but nothing happens when I add comments to sub-tasks. Even one I have created AFTER adding this in. 

 

Can anyone see what I'm doing wrong?


For reference the whole script that I'm adding in is:

import com.atlassian.jira.ComponentManager
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 = ComponentManager.instance.commentManager

@Override
void workflowEvent(IssueEvent event) {
// only one central way...
this.customEvent(event)
}

@Override
void customEvent(IssueEvent event) {
// set explicit to debug
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "Event: \"${ComponentManager.instance.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.author, comment.updateAuthor, comment.body, comment.groupLevel, comment.roleLevelId, comment.created, comment.updated, true, true)
log.debug ("Created comment on ${parent.key}")
}
}
}

 

 

Thanks, 

1 answer

0 votes
Ivan Tovbin
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.
March 9, 2019

Hi,

It seems there's a problem whilst you try to initialize 'commentManager' variable.

Try the following:

First add this import:

import com.atlassian.jira.component.ComponentAccessor

Then replace this line:

 CommentManager commentManager = ComponentManager.instance.commentManager

with this:

CommentManager commentManager = ComponentAccessor.getCommentManager() 
anthony_butler March 11, 2019

Thanks for the reply, I've done all of that and still nothing is showing on the parent task?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events