How can I duplicate an attachment to linked issue on the same project. I already created a workflow, screen and transition. I need a post-function for this. The code I currently use is like this and doesn't work:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.attachment.Attachment
import com.atlassian.jira.user.ApplicationUser
def issue = issue
if (!issue) {
log.error("Issue context is not available. This script must be run in the context of an issue.")
return
}
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def attachmentManager = ComponentAccessor.attachmentManager
def existingAttachments = issue.getAttachments()
def linkedIssues = issue.getLinkedIssues("blocks")
linkedIssues.each { linkedIssue ->
def linkedAttachments = linkedIssue.getAttachments()
linkedAttachments.each { linkedAttachment ->
def isDuplicate = existingAttachments.any { attachment ->
attachment.filename == linkedAttachment.filename &&
attachment.filesize == linkedAttachment.filesize &&
attachment.mimetype == linkedAttachment.mimetype
}
if (!isDuplicate) {
attachmentManager.copyAttachment(linkedAttachment, currentUser, issue.key)
}
}
}