How to create an issue with an image attached in one operation?

Hi there,

I want to create an issue where the description includes an image tag like !image.png!. The image should be attached to that issue within the create operation. This is to ensure that the image is already there when the create postfunctions will run. E.g. the create notification should render and contain this image.

I tried this two calls.

final Issue issue = this.getIssueManager().createIssueObject(reporter, fields);

// postfunctions will run here
final ChangeItemBean cib = attachmentManager.createAttachment(file, filename, contentType, reporter, issue);

When doing so the issue is created without the attachment. The notification mail say:

"Unable to render embedded object: File (image.png) not found."

That is because the second call to the attachmentManager updates the issue with the image after it is already created.

In inverse order an exception is thrown claiming that the issue where to attach the image does not exists.

final ChangeItemBean cib = attachmentManager.createAttachment(file, filename, contentType, reporter, issue);

// Exception is thrown.

final Issue issue = this.getIssueManager().createIssueObject(reporter, fields);

Can anyone point me to the right direction?


Cheers,

Jan

2 answers

1 accepted

You have to go with IssueService issueService.validateCreate(..), TemporaryAttachmentsMonitor, IssueService.IssueResult. QuickCreateIssue.java give some hints.

You could add "Attachments" to your create screen and add a validator on create that requires the attachments field..

I have to use the Java API from Jira to solve my problem. However I tried to create an issue with an attached image over the GUI create screen. This works well and the image is attached within the create operation.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,826 views 12 18
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot