Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

...

...

...

...

...

Abstract

This code snippet copies the attachments Attachments of all the first linked issue issues to the current issue. Since currently copying and setting of attachments is not supported until JMWE-504 is implemented, you can use this snippet to copy the attachments of an issue.

Logic

Fetch the attachments of the linked issues, linked to the current issue with a specific link type and use the AttachmentManager to set copy the attachments of to the issue.

Snippet

Code Block
languagegroovy
linenumberstrue
//DefineInitialize the attachmentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.AttachmentManager
AttachmentManager attachmentManager = ComponentAccessor.getAttachmentManager()

//Define a variable to store the attachments variable

def attach = []
if(issue.getLinkedIssues("<Link type name>")){
//Fetch the attachments of the linked issue and store them in the attach variable

 attach = issue.getLinkedIssues("<Link type name>").first()each{
    attach += it.get("attachment")
  }
}
//Add each attachment to the issue
attach.each{
  attachmentManager.copyAttachment(it,currentUser,issue.key)
}


Info

You can copy the Attachments of all the linked issues to the current issue, other than Parent-Subtask and Epic-Story link types, by not specifying the link type as issue.getLinkedIssues()

Placeholders

Placeholder

Description

Example

<Link type name>Name of the link type nameis cloned by

Examples

The output of the code snippet is a collection of attachments Attachments which you could use in a Groovy expression, for example. to Set , to copy the Attachments of a linked to an issue in one of the Set field value post-functions or the Create issue the Scripted Groovy post-function under the Set fields of new issue section. Examples:

  • Copy the Attachments of the issue to current issue linked to the newly created issue
  • Copy the Attachments of the issue to a linked issue

References