Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,557,284
Community Members
 
Community Events
184
Community Groups

Copy attachments from one issue to another linked issue in another project

Edited

Is there some kind of post function or listener that enables copying of attachments form one issue to his linked issue in another project? I would like to do it with ScriptRunner for cloud.

2 answers

1 accepted

3 votes
Answer accepted
Jack Brickey
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 01, 2021

OOTB I don’t believe there is a solution for this. I would suggest Automation but there is an open request for this - AUT-1030 . There are addon solutions, e.g. Exlate and probably scriptrunner.

I have scriptrunner and that is the way I would like to implement solution. Do you know how to implement it?

 

Kr,

Filip

Jack Brickey
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 01, 2021 • edited

A search in the Community search bar returns this - https://community.atlassian.com/t5/forums/searchpage/tab/message?advanced=false&allow_punctuation=false&q=Copy+attachments+scriptrunner+ 

if you find the right solution for you please add to the post for future searches.

Laura Campbell _Elements_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 01, 2021

Hi @Filip Škledar ,

If you're open to trying another app, Elements Copy & Sync allows you to copy attachments between linked issues.

For example, if you use the app to clone a JSM ticket into a software project (or just create a linked ticket), you can have attachments from the JSM ticket copied over to the new issue. This works even with new attachments, like when a customer provides something new on the JSM ticket.

If you have any trouble setting it up, don't hesitate to contact the Elements support team.

Laura

Like # people like this

If still needed, I can share code for this :) 

Lukasz Grobelny, Yes, Please share your code for this. Thank you so much.

Like Ziyarat Mahmudzadeh likes this

@Lukasz Grobelny , can you please share the code.

Cloud or server?

So I added a custom field (select list) where the user was able to select if he want to copy the attachment as well, if he selected attachments the script would go like this:

if(selectedFields.contains("Załączniki")){
for(int i = 0; i < attachment.size(); i++ ){
def attId = attachment.id[i]
def att = Unirest.get('/rest/api/2/attachment/' + attId).asObject(Map).body
def downloadUrl = attachment.content[i]
def readFileResp = Unirest.get(downloadUrl).asBinary()
log.warn(downloadUrl)
def response = Unirest.post('/rest/api/2/issue/' + createdIssueKey + '/attachments')
.header("Accept", "application/json")
.header("X-Atlassian-Token", "nocheck")
.field("file", readFileResp.body, att.title.toString())
.asObject(Map)

}
}

Hi Lukasz could you share a code you have for server Jira version? Thank you in advans

Hi, sorry, missed this... do you still need it?

Yes, please.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.context.IssueContext
import com.atlassian.jira.issue.context.IssueContextImpl
import com.atlassian.jira.issue.fields.config.manager.PrioritySchemeManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.AttachmentManager
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import org.apache.log4j.Logger
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager

/Puling the CF
/
def summary = issue.getSummary()
def assignee = issue.getAssignee().getDisplayName()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def commentManager = ComponentAccessor.getCommentManager()
def existngComments = commentManager.getComments(issue);
def originalIssueType = issue.getIssueType().getName()
def originalDescription = issue.getDescription()
def priority = issue.getPriority().getName()

//Project picker - we need to select a destination project
def cField = customFieldManager.getCustomFieldObject("customfield_10201")
def projectKeyValue = (String) issue.getCustomFieldValue(cField)
//Cleaning the value
def projectKeyFromPicker = projectKeyValue.minus("Project: ")

//Selector of what will be moved - Checklist field on which users can elect what they want to mowe - comments etc
def additionalFieldsSelector = customFieldManager.getCustomFieldObject("customfield_10300")
def additionalFields = issue.getCustomFieldValue(additionalFieldsSelector) as String

// Reporter
final reporterKey = issue.getReporter().getKey()

//Priority
final priorityName = 'Major'

//Variales
def subTasks = issue.getSubTaskObjects()
def issueService = ComponentAccessor.issueService
def constantsManager = ComponentAccessor.constantsManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def prioritySchemeManager = ComponentAccessor.getComponent(PrioritySchemeManager)
def project = ComponentAccessor.projectManager.getProjectObjByKey(projectKeyFromPicker)
def issueType = constantsManager.allIssueTypeObjects.findByName(originalIssueType)

//Logged in user will be used
def reporter = ComponentAccessor.userManager.getUserByKey(reporterKey) ?: loggedInUser
def assignableUser = ComponentAccessor.userManager.getUserByName(assignee) ?: loggedInUser

// Setting up the priority
def issueContext = new IssueContextImpl(project, issueType) as IssueContext
def priorityId = constantsManager.priorities.findByName(priority)?.id ?: prioritySchemeManager.getDefaultOption(issueContext)

//creating the issue
def issueInputParameters = issueService.newIssueInputParameters().with {
setProjectId(project.id)
setIssueTypeId(issueType.id)
setReporterId(reporter.name)
setSummary(summary)
setPriorityId(priorityId)
setAssigneeId(assignableUser.name)
setDescription(originalDescription)
}

def validationResult = issueService.validateCreate(loggedInUser, issueInputParameters)
assert validationResult.valid : validationResult.errorCollection

def result = issueService.create(loggedInUser, validationResult)
assert result.valid : result.errorCollection
def newIssue = result.getIssue()

log.warn("${result.getIssue()} + was created" )

//Atthachment copy
def issueObject = issue.getAttachments()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
AttachmentManager attachmentManager = ComponentAccessor.getAttachmentManager();
log.warn(issueObject.getAt(0))
attachmentManager.copyAttachments(issue, currentUser,result.getIssue().key)

//Comment Copy
if(additionalFields.contains("Komentarze")){
for(int i = 0; i < existngComments.size(); i++){
def commentAuthor = existngComments.getAt(i)getAuthorApplicationUser()
def newBody = existngComments.getAt(i).getBody()
commentManager.create(newIssue,commentAuthor,newBody,true)
log.warn(existngComments.getAt(i).getBody())
}
}
//Issue link

// Link type
final String issueLinkName = "Duplicate"

//sequence
final Long sequence = 1L

def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)

def availableIssueLinkTypes = issueLinkTypeManager.issueLinkTypes
def linkType = availableIssueLinkTypes.findByName(issueLinkName)

ComponentAccessor.issueLinkManager.createIssueLink(newIssue.id, issue.id, linkType.id, sequence, loggedInUser)
Like Ingo Jurz likes this

The way it works - the user selects Copy on the issue.

On a Copy screen, he can select the Destination project; on the checklist, he can choose what will be moved.

 

You can trim it down just to copy the issue without fireworks

Suggest an answer

Log in or Sign up to answer