Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Copy attachment with issue link in two project

Andrey Miranda Diaz November 29, 2023

Can you help us with the following requirement :

 

We are using the clone issue link to clone tickets through a transition.

 

After cloning the ticket, it is required that the comments and attachment can be sent in both directions.

 

You can also synchronize attachments when they are added to comments .

 

 

I am trying with the following script by placing a code in script runner in a listering that is activated when I add an attachment to the parent ticket but when I add a new attachment it duplicates the ones that have been sent previously .

 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.attachment.Attachment
import com.atlassian.jira.issue.AttachmentManager
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.user.ApplicationUser
import org.ofbiz.core.entity.GenericValue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue




//def attachmentManager = ComponentAccessor.getAttachmentManager()
//def lastAttachment = attachmentManager.getAttachments(issue).last()
//def issue = ComponentAccessor.getIssueManager().getIssueObject() //dummy issue - delete this
//String[] validLinkTypes = ["moved to", "cloned to"]



def linker = ComponentAccessor.getIssueLinkManager()
def commentMgr = ComponentAccessor.getCommentManager()
def issue = event.issue as MutableIssue
def project = issue.getProjectObject().getKey()
def attachmentManager = ComponentAccessor.getAttachmentManager()


def lastAttachment = attachmentManager.getAttachments(issue).last()

def issueLinks = linker.getOutwardLinks(issue.getId())

def subElements = issueLinks.findAll { it.issueLinkType.name.contains('cloned to') && it.issueLinkType.name.contains('moved to')

def newComment = event.getComment()
def originalAuthor = newComment.getAuthorApplicationUser()
def commentBody = newComment.getBody()

/*
subElements.each {
if( commentBody != "")
{
commentMgr.create(it.getDestinationObject(), originalAuthor, commentBody , false)
}

}*/

//subElements.each {
if(lastAttachment)
{
attachmentManager.copyAttachment(lastAttachment, originalAuthor, it.getDestinationObject().key)
}
//}
}

Do you have any suggestions on how to solve this requirement?

0 answers

Suggest an answer

Log in or Sign up to answer