Questions for Confluence license has expired.

Please purchase a new license to continue using Questions for Confluence.

How to read Attachment by advanced scripting during the first transition "Create"

 
1
0
-1

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.

  1. Juan Grases

    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?

  2. Anatoly Ekert

    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. 

  3. Roman

    hey Anatoly Ekert . Is this for Jira Cloud or Server? 

  4. Anatoly Ekert

    hi. this is for Server

  5. Roman

    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
    }




  6. Anatoly Ekert

    Roman, I do not understand where it came from "blobMetadataList "? There is an error at this point.

  7. Juan Grases

    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?

  8. Anatoly Ekert

    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

CommentAdd your comment...

2 answers

  1.  
    3
    2
    1

    Hi again,

    Looks like this script would help you on what you want:


    //Incoming script
    replica.addedAttachments.collect{it.getRemoteIdStr()}.each{ attachmentId ->
      if(attachmentId){
        def filePath = blobMetadataList.find{it.getBlobId() == attachmentId}?.getBlobFilePath()
        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
        }else{
          throw new Exception("File Path not found")
        }
      }
    }

    Let me know if it helps,

    Juan

    1. Laith Ata

      Hi,

      it worked. Thanks again! 

      Cheers,
      Laith 

    CommentAdd your comment...
  2.  
    1
    0
    -1

    Hi!

    From the incoming processor you have available metadata of the attachments coming from the other side such as mimetype, filename, filesize, created (date).


    You can access it like this:


    def remoteNewAttachments = replica.addedAttachments
    
    def fileNames = remoteNewAttachments.collect{it.filename} // Results in a list of file names

    Which info you need from the received attachments?


    Best regards,

    Juan

    1. Anatoly Ekert

      Yes, I can get the file name, there is no problem with that. But I need to get the path to the file and read the file and get the data from it.

    CommentAdd your comment...