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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage
Highlighted

How to copy comments with attachments to last linked issue - ScriptRunner Edited

Here's how to copy comments with attachments to the last linked issue:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.getCommentManager()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def attachmentManager = ComponentAccessor.getAttachmentManager()
def user = ComponentAccessor.getJiraAuthenticationContext().loggedInUser

def issue = event.issue as Issue

lastComment = commentManager.getLastComment(issue)
body = lastComment.getBody()
author = lastComment.getAuthorApplicationUser()

def linkedIssue = issueLinkManager.getLinkCollection(issue, user).getAllIssues().last()

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

attachmentManager.copyAttachment(lastAttachment, user, linkedIssue.key)

commentManager.create(linkedIssue, author, body, false

 

1 comment

Try this:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.attachment.Attachment

def commentManager = ComponentAccessor.getCommentManager()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def attachmentManager = ComponentAccessor.getAttachmentManager()
def user = ComponentAccessor.getJiraAuthenticationContext().loggedInUser

def issue = event.issue as Issue

def lastComment = commentManager.getLastComment(issue)
def body = lastComment.getBody()
def author = lastComment.getAuthorApplicationUser()

Issue linkedIssue = issueLinkManager.getLinkCollection(issue, user).getAllIssues().last()
def linkedIssueLastComment = commentManager.getLastComment(linkedIssue).getBody()
//make sure that the listener won't go in a loop
if(linkedIssueLastComment != body){
List<Attachment> lastAttachment = attachmentManager.getAttachments(issue)

lastAttachment.each{ attachment ->
attachmentManager.copyAttachment(attachment, user, linkedIssue.key)
}

commentManager.create(linkedIssue, author, body, false)
}

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Do Not Lose your Customer’s Trust

Missing deadlines is one of the biggest problems every team lead wants to avoid when dealing with managed services. When the customer contracts your company to help with IT services it is expected th...

341 views 0 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you