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.
Hello @Nina Zolotova
Can you add some logs in the script so that trouble shooting becomes easier, also I guess these 2 are separate listeners.
For copying from SD to MA, can you test with getInwardLinks and see what the result is as the listener if configured for only SD project then it should do the trick.
What you can also try is use "getLinkCollection" instead of inward and outward links
And you will get LinkCollection
And then just use .each opetaror and add the comments on the linked issue which have the project key as that of the target project.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Discover how Atlassian is revolutionizing service management with cutting-edge solutions for AI-powered support, HR Service Management, or DevOps connectivity.
Register here ⬇️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.