Hi,
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()
@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: \"${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