Originally asked by Anatoly Ekert on 27 May 2020 (original question)
I have the following problem:
I sync an issue with attachment into a new issue and I wish to be able to read the attachment by the first transition “create”, which means before the first status (Create Issue / Open / …) is set.
I understand from my readings (on the forums) that the attachment are not yet completely available by that first transition, but it is possible to access some equivalent temporary attachment.
However all my attempts have failed.
Any ideas how to do get the attachment in the temporary directory? Code snippets, pointers? Thank you.
Comments:
Juan Grases commented on 29 May 2020
Hi! Could you describe exactly the use case? Why do you need to have the attachment available before creating the issue and what would you like to do with it?
Anatoly Ekert commented on 02 June 2020
Hi. I do not need access to the attachment before the creation of the Issue, but in the process of creation. Because I have to fill in the fields of the Issue partially from this attachment.
Roman commented on 02 June 2020
hey Anatoly Ekert . Is this for Jira Cloud or Server?
Anatoly Ekert commented on 02 June 2020
hi. this is for Server
Roman commented on 02 June 2020
Anatoly Ekert Can you try
def attachmentId = replica.addedAttachments.find { it.filename == "Foo.pdf" }?.id
def filePath = blobMetadataList.find {it.blobId == attachmentId}?.blobFilePath
if (filePath) {
def f = new java.io.File(filePath)
// feel free to use any method to read in stuff into memory: https://stackoverflow.com/questions/326390/how-do-i-create-a-java-string-from-the-contents-of-a-file
}
Anatoly Ekert commented on 02 June 2020
Roman, I do not understand where it came from "blobMetadataList "? There is an error at this point.
Juan Grases commented on 02 June 2020
blobMetadataList should be an accessible variable in the context of the script (Jira Server incoming script), it represent the list of attachments you are receiving from the other side. Are you sure you are using the right name of the file on the first line of the proposed script? What is exactly the error?
Anatoly Ekert commented on 03 June 2020
I figured out blobMetadataList, now everything works, but unfortunately there is no result. I get Null. I checked the file name is correct and it exists in the original Issue.
2020-06-03 06:04:45,931+0000 pool-38-thread-1 INFO anonymous [com.exalate.script] mas filePath= null
2020-06-03 06:04:45,931+0000 pool-38-thread-1 INFO anonymous [com.exalate.script] mas attachmentId= null