Hello everyone.
I have two projects - SD and MA. On a particular step of SD workflow issues are cloned to project MA.
I want to sync comments between an original issue and a cloned one, so I've written a listener.
If I add a comment to project MA issue, this code works correctly (copies comment from MA to SD):
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.AttachmentManager
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.user.ApplicationUser
import org.ofbiz.core.entity.GenericValue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue;
def linker = ComponentAccessor.getIssueLinkManager()
def attachmentMgr = ComponentAccessor.getAttachmentManager()
def commentMgr = ComponentAccessor.getCommentManager()
def issue = event.issue as MutableIssue
def newComment = event.getComment()
def originalAuthor = newComment.getAuthorApplicationUser()
def commentBody = newComment.getBody()
linker.getOutwardLinks( issue.getId() ).each {
if( commentBody != "" )
{
commentMgr.create(it.getDestinationObject(), originalAuthor.getName(), commentBody , true)
}
}
For copying comments from SD to MA I only changed getOutwardLinks to getInwardLinks
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.AttachmentManager
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.user.ApplicationUser
import org.ofbiz.core.entity.GenericValue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue;
def linker = ComponentAccessor.getIssueLinkManager()
def attachmentMgr = ComponentAccessor.getAttachmentManager()
def commentMgr = ComponentAccessor.getCommentManager()
def issue = event.issue as MutableIssue
def newComment = event.getComment()
def originalAuthor = newComment.getAuthorApplicationUser()
def commentBody = newComment.getBody()
linker.getInwardLinks( issue.getId() ).each {
if( commentBody != "" )
{
commentMgr.create(it.getDestinationObject(), originalAuthor.getName(), commentBody , true)
}
}
and it doesn't work at all. It adds comment to SD-issue more than 100 times, but doesn't copy it to MA-issue...
Please help me to fix it.