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
You can achieve the same using the listener as well. I have explained the steps briefly in the below blog post for your reference,
Hi Wojciech,
Do you wish to 'copy' the comment added on the parent issue to all its children? Could you elaborate?
Cheers,
Helmy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.watchers.WatcherManager
import com.atlassian.jira.user.ApplicationUser
import 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 = it
log.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"
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.watchers.WatcherManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.comments.Comment;
String[] taskInSecondLine = ["7"]
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()
def parent = event.issue.parentObject
issue.getParentObject().each{
Issue sourceIssue = it
log.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.commentManager
if(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.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
def commentManager = ComponentAccessor.commentManager
ApplicationUser currentUser = event.getUser()
ApplicationUser epmjraplugin = ComponentAccessor.getUserManager().getUserByName("w.woytynowsk")
if(event.issue.isSubTask() && event.comment){
def parent = event.issue.parentObject
def 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 me
If it was possible to insert screenshots I would show what the first way does and what the second way does
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.