This document is obsolete. JMWE now supports copying of attachments across issues in the post-functions.
Abstract
This code snippet copies Attachments to the current issue from issues linked to it with a specific link type. Since currently copying and setting of attachments is not supported until JMWE-504 is implemented, you can use this snippet to copy the attachments.
Logic
Fetch the attachments of the linked issues, linked to the current issue with a specific link type and use the AttachmentManager
to copy them.
Snippet
//Initialize the attachmentManager import com.atlassian.jira.issue.AttachmentManager AttachmentManager attachmentManager = ComponentAccessor.getAttachmentManager() //Define a variable to store the attachments def attach = [] if(issue.getLinkedIssues("<Link type name>")){ //Fetch the attachments of the linked issue and store them in the attach variable issue.getLinkedIssues("<Link type name>").each{ attach += it.get("attachment") } } //Add each attachment to the issue attach.each{ attachmentManager.copyAttachment(it,currentUser,issue.key) }
By not specifying the link type, as issue.getLinkedIssues(),
you can copy the Attachments of all the linked issues of the current issue, other than the Parent-Subtask and Epic-Story links.
Placeholders
Placeholder | Description | Example |
---|---|---|
<Link type name > | Name of the link type | is cloned by |
Examples
The outcome of the code snippet is the copy of Attachments to an issue in the Scripted Groovy post-function:
- Copy the Attachments of the current issue to its newly created linked issue created using the Create issue post-function
- Copy the Attachments of the issue to a linked issue
References
Related articles
-
-
Link parent of the current sub-task to new issue in “Create / Clone issue(s) (JMWE app)” post-function (JMWE for Jira Server and Data Center)
-
Set assignee of the issue based on day of the month. (JMWE for Jira Server and Data Center)
-
-
Code snippet to get the default value of a custom field (JMWE for Jira Server and Data Center)
-
Code snippet to add a link to a workflow transition in the email (JMWE for Jira Server and Data Center)
-
Assign the related issues of the current issue to users in a Project role in Round Robin method (JMWE for Jira Server and Data Center)
-
Set an Estimate of the issue to the difference of two specific dates - Groovy (JMWE for Jira Server and Data Center)
-
Set a date field to today's date - Groovy (JMWE for Jira Server and Data Center)
-
Concatenate text fields without null - Groovy (JMWE for Jira Server and Data Center)
-
Set Component/s field from a Cascading field (JMWE for Jira Server and Data Center)
-
Find the next unreleased version (JMWE for Jira Server and Data Center)
-
Set a version field to versions of all its linked issues (JMWE for Jira Server and Data Center)
-
Fetch the value of a multi-value field when you know it has only one value (JMWE for Jira Server and Data Center)
-
Checking the value of a multi-valued field (JMWE for Jira Server and Data Center)