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:
Hi @Emre Ünal
Could you try the below code?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.attachment.Attachment
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def attachmentManager = ComponentAccessor.attachmentManager
def issueLinkManager = ComponentAccessor.issueLinkManager
if (!issue) {
log.error("Issue context is not available. This script must be run in the context of an issue.")
return
}
def linkedIssues = issueLinkManager.getInwardLinks(issue.id).findAll { it.issueLinkType.name == "blocks" }.collect { it.sourceObject }
// Check if there are attachments to copy
linkedIssues.each { linkedIssue ->
linkedIssue.getAttachments().each { linkedAttachment ->
def isDuplicate = issue.getAttachments().any { attachment ->
attachment.filename == linkedAttachment.filename &&
attachment.filesize == linkedAttachment.filesize
}
if (!isDuplicate) {
// Copy the attachment
def file = attachmentManager.getAttachmentFile(linkedAttachment)
attachmentManager.createAttachment(file, linkedAttachment.filename, linkedAttachment.mimetype, currentUser, issue)
log.info("Copied attachment '${linkedAttachment.filename}' from issue '${linkedIssue.key}' to '${issue.key}'.")
}
}
}
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.