Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Update Issue after create attachment in listener

Franz Engel April 17, 2019

Hello,

 

I have a problem with create and insert a pdf via a listner. If an user uploads a pdf one of my scripts is started to copy the pdf and inserting an annotation and safe it as well in the same issue. That works good, but I have no idea how to update my issue. I found examples for costume fields like this:

issueInputParameters.addCustomFieldValue(projectPage.getIdAsLong(), pageUris["mainPageUri"])
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def validationResult = issueService.validateUpdate(loggedInUser, issue.getId(), issueInputParameters)

 But I don't know how to update the attachment field.

1 answer

0 votes
Prakhar Srivastav {Appfire}
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 17, 2019

@Franz Engel 

 

You need AttachmentManager to upload attachment to an issue.

https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/issue/AttachmentManager.html

It has copy , create and delete attachment methods that you can user accordingly.

 

Regards

Prakhar

Franz Engel April 17, 2019

I did so.

CreateAttachmentParamsBean createAttachment = new CreateAttachmentParamsBean.Builder(
attachmentNew,
issue.key + "_annotated.pdf",
invoice.mimetype,
invoice.authorObject,
issue
).build()

attachmentManager.createAttachment(createAttachment)

But my problem is, that the issue is not updated with that method. So the history don't show me, that a new pdf is inserted. And I think that could lead to some problems in the database. 

Prakhar Srivastav {Appfire}
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 17, 2019

@Franz Engel 

Make sure the issue is persisted in the database before you try to create attachment. Try to log if there is any exception and share the log.

 

Regards

Prakhar

Franz Engel April 17, 2019

I'm sure that the issue is persisted in the database. I don't create the issue. The issue is already there. I get no exception. My script is running well. The only thing is, that I think I have to make something like

issueService.validateUpdate

after changing something in my issue via a listener script. 

Suggest an answer

Log in or Sign up to answer