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

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


1 badge earned


Participate in fun challenges

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


Gift kudos to your peers

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


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!


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
Community Members
Community Events
Community Groups

Adding an attachment to a comment

I use this method to add an attachment to an issue:

def attachmentManager = ComponentAccessor.getAttachmentManager()
def bean = new CreateAttachmentParamsBean.Builder(tempFile,
"keylead_"+reqCheckJSON["id"]+".pdf", //resultMap["set"][0]['note']+

def changeItemBean= attachmentManager.createAttachment(bean)

 But customers can't see the attachment.

I wondered maybe I should add the attachment as a comment. 

I didn't find a way to make attachment visible to customers. Neither was I able to attach it as a comment.

What do you think is the right way and how?

2 answers

1 accepted

1 vote
Answer accepted

Found the solution: After attaching the file to issue, a new comment should be added to it containing attached file name by [^ and ] tags like:

Attachment added [^filename.pdf].

This solution is only for ScriptRunner Server?

Any suggestions to use it on ScriptRunner Cloud ?

Thanks in advance.

0 votes
DPKJ Community Leader Aug 19, 2019

Try something like this,

def attachmentManager = ComponentAccessor.getAttachmentManager();
def issueManager = ComponentAccessor.getIssueManager();

CreateAttachmentParamsBean bean = new CreateAttachmentParamsBean.Builder(
tempFile, fileName, 'application/pdf', user, issue).build()
ChangeItemBean changeItemBean= attachmentManager.createAttachment(bean) issueManager.updateIssue(user,issue,new EventDispatchOption.Factory().get(EventType.ISSUE_UPDATED_ID),true)  

Thanks. Can you please give me a brief explanation on what it does? Or lead me to a book or other resource which explains the matter.

DPKJ Community Leader Aug 21, 2019

There is no specific book, you can learn it from Jira's java api.

What it does is (line by line),

  • Create instance of attachment manager
  • create instance of issue manager
  • Create new attachment bean object (a placeholder for attachment)
  • Create new change item (as we want to update issue)
  • Call updateIssue on issue manager.
DPKJ Community Leader Aug 21, 2019

You can upvote or accept answer if it helped you.

  • Call updateIssue on issue manager.

What this line exactly does?

I won't forget to upvote after I tested the solution. Thank you.

DPKJ Community Leader Aug 21, 2019

What we have done before this like is update issue object in issue to have an attachment associated with it.

But to save these changes that we have to done to issue object has to be transferred to database. So we call,

issueManager.updateIssue(user,issue,new EventDispatchOption.Factory().get(EventType.ISSUE_UPDATED_ID),true)

This method update issue object to database and raise and event so other jira services can know that issue has been updated.

Unfortunately nothing happened after I added that line.

DPKJ Community Leader Aug 24, 2019

I think you need to confirm ScriptRunner team, this seems to be working fine on my instance.

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events