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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How to copy all Jira ticket issue attachments and file content as it is in another Jira cloud without any issues?
Ans:-
(go to your project ) box tracking >- project setting >- permissions >- actions >- edit permissions > Browse Projects > give public access to that project
here you will be good to go with export and import issues without any error
note:-- You're in a team-managed project and can't see this option for that we need a company-managed project
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If still needed, I can share code for this :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cloud or server?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Lukasz could you share a code you have for server Jira version? Thank you in advans
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, sorry, missed this... do you still need it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.