I have Script Runner and I would like to use Scirpt Listener so that every time I add a comment to the main ticket it moves to the sub-task
Hi Wojciech,
Do you wish to 'copy' the comment added on the parent issue to all its children? Could you elaborate?
Cheers,Helmy
Not really. I would like to move comments both ways, from parent issue to subtask but also the other way around. If someone adds comment in parent issue then listener copies it to subtask, if someone adds comment to subtask then it copies it to parent.
I did it two ways. The first way works even though it is in two separate listener.
First way is:
-----------------------------------------------------------------1. first listener "Copy Story to subtask"
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.issue.comments.CommentManagerimport com.atlassian.jira.issue.link.IssueLinkManagerimport com.atlassian.jira.issue.watchers.WatcherManagerimport com.atlassian.jira.user.ApplicationUserimport com.atlassian.jira.issue.comments.Comment;
String[] taskInSecondLine = ["5"]
Issue issue = event.getIssue()CommentManager cm = ComponentAccessor.getCommentManager();WatcherManager wm = ComponentAccessor.getWatcherManager()ApplicationUser currentUser = event.getUser()ApplicationUser epmjraplugin = ComponentAccessor.getUserManager().getUserByName("epmjraplugin")
if(!currentUser.equals(epmjraplugin)) {def comment = event.getComment()IssueLinkManager ilm = ComponentAccessor.getIssueLinkManager()
issue.getSubTaskObjects().each{Issue sourceIssue = itlog.error(sourceIssue)log.error(sourceIssue.getIssueTypeId())log.error("status źródła " + sourceIssue.getStatusId())String zamknietyStatus = "6"if(sourceIssue.id!=issue.id && taskInSecondLine.contains(sourceIssue.getIssueTypeId()) && sourceIssue.getStatusId()!=zamknietyStatus )cm.create(sourceIssue,epmjraplugin, "Komentarz dodany przez: "+event.getUser().getDisplayName()+" \nTreść komentarza: " +comment.getBody(), true)}}
2. Second listener "Copy subtask to Story"
String[] taskInSecondLine = ["7"]
if(!currentUser.equals(epmjraplugin)) {def comment = event.getComment()IssueLinkManager ilm = ComponentAccessor.getIssueLinkManager()def parent = event.issue.parentObjectissue.getParentObject().each{Issue sourceIssue = itlog.error(sourceIssue)log.error(sourceIssue.getIssueTypeId())log.error("status źródła " + sourceIssue.getStatusId())String zamknietyStatus = "6"if(sourceIssue.id!=issue.id && taskInSecondLine.contains(sourceIssue.getIssueTypeId()) && sourceIssue.getStatusId()!=zamknietyStatus )cm.create(sourceIssue,epmjraplugin, "Komentarz dodany przez: "+event.getUser().getDisplayName()+" \nTreść komentarza: " +comment.getBody(), true)}}
-----------------------------------------------------------------------------The second way is:
1.Copy comment from Story to sub-task 2
import com.atlassian.jira.component.ComponentAccessor
def commentManager = ComponentAccessor.commentManagerif(event.issue.subTaskObjects && event.comment){event.issue.subTaskObjects.each { subtask ->def newCommnet = commentManager.create(subtask,event.user,"Comment from parent: $event.issue.key:\n{quote} $event.comment.body {quote}",event.comment.groupLevel,event.comment.roleLevelId,true)}}
Copy comment from subtask to Story 2
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.user.ApplicationUserdef commentManager = ComponentAccessor.commentManagerApplicationUser currentUser = event.getUser()ApplicationUser epmjraplugin = ComponentAccessor.getUserManager().getUserByName("w.woytynowsk")
if(event.issue.isSubTask() && event.comment){def parent = event.issue.parentObjectdef newCommnet = commentManager.create(parent,event.user,"Comment from sub-task: $event.issue.key:\n{quote} $event.comment.body {quote}",event.comment.groupLevel,event.comment.roleLevelId,true)}
----------------------------------------------------------------------------------
Only the second way when I turn on both listeners it does a loop and adds comments until I turn off the listener.
What I would like to achieve is to combine the first way with the second because in the first one you can see that the user automatically inserts a comment and that's great but you can't see that it goes from a subtask with a specific issue number.
I hope I did not confuse you too much.Thank you. very much that you want to help meIf it was possible to insert screenshots I would show what the first way does and what the second way does
You can achieve the same using the listener as well. I have explained the steps briefly in the below blog post for your reference,
https://codetolive.in/jira/How-to-use-a-JIRA-custom-listener-to-copy-comments-from-the-parent-issue-to-all-sub-tasks/
It looks like you're new here. Sign in or register to get started.