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

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
DPK J 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.

DPK J 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.
DPK J 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.

DPK J 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.

DPK J 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
Community showcase
Published in Marketplace Apps & Integrations

🤺 Atlympic Event: Partnerships

Hello Community!  Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...

22 views 0 0
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