Hello,
We are trying to copy attachments from one issue to another. The issues should be linked with the "Parent/Child" issue link, and we would probably keep 2 script listeners to always keep the issues in sync between 2 projects.
What we have:
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.attachment.Attachment
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 commentMgr = ComponentAccessor.getCommentManager()
def issue = event.issue as MutableIssue
def project = issue.getProjectObject().getKey()
def attachmentManager = ComponentAccessor.getAttachmentManager()
def lastAttachment = attachmentManager.getAttachments(issue).last()
def issueLinks = linker.getOutwardLinks(issue.getId())
def subElements = issueLinks.findAll { it.issueLinkType.name.contains('Parent/Child') && it.destinationObject.getProjectObject().getKey() == 'Test'}
def newComment = event.getComment()
def originalAuthor = newComment.getAuthorApplicationUser()
def commentBody = newComment.getBody()
subElements.each {
if( commentBody != "")
{
commentMgr.create(it.getDestinationObject(), originalAuthor, commentBody , false)
}
}
subElements.each {
if(lastAttachment)
{
attachmentManager.copyAttachment(lastAttachment, originalAuthor, it.getDestinationObject().key)
}
}
You can ignore the comments part, but since there isn't an issue attachment added event, I'm not sure how else to do this.
The script does not give any errors, but attachments are not copied at all.
Thank you in advance!