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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

81 views 0 5
Read article

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