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

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

how to attache attachment in comment


i want to attach pdf attachment(link) in comment using 



def commentManager = ComponentAccessor.getCommentManager()
def textComment = fnm + " has been added to the issue"
commentManager.create(issue, currentUser, textComment, null, null, new Date(), true)


above code create comment as "text" not " pdf link",like below


2 answers

1 accepted

Hi @Sneha Gole 

For your requirement, I assume you are using a Listener to trigger the comment update.

You could try something like this:-

import com.atlassian.jira.component.ComponentAccessor

def issue = event.issue

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def attachmentManager = ComponentAccessor.attachmentManager
def commentManager = ComponentAccessor.commentManager

def attachments = attachmentManager.getAttachments(issue)

def latestAttachment = attachments.findAll {
}.sort { it.created }.last()

def commentBody = "file has been added to the comment"
commentManager.create(issue,loggedInUser, "[^${latestAttachment.filename}] ${commentBody}", false)

Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a print screen of the listener configuration:-


Below are a few print screens of the tests:-

1) First, when the issue is created, no attachments are added, as shown below.


2) Once an attachment is added, refresh the page, and you will see the comment is automatically added, as shown below.


3) Adding other pdf attachments, and the comment is updated as well as shown below:-


I hope this helps to solve your question. :)

Thank you and Kind Regards,


thank you so much for your effort   @Ram Kumar Aravindakshan _Adaptavist_  it work like wonders !!!!

Hi @Sneha Gole ,

What is the def for variable fnm? Your code tries to append fnm and the string.

hii @Niranjan ,

thanks for quick reply ,

i have pass file path in fnm (/opt/atlassian/jira/temp/EMPLOYEEE.pdf)

@Sneha Gole - Should you not be using ComponentAccessor.attachmentManager.createAttachment  as you are actually creating an attachment ? 

@Niranjan ,

i am attaching pdf file to issue and i want to create comment ___ pdf file is attached .


Suggest an answer

Log in or Sign up to answer

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