Forums

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

read csv fle form issue attachment using scriptrunner

sgole
Contributor
March 1, 2020

Hii,,

can anybody plz help me with this , i want to read csv file from attachment using script runner . 

1 answer

0 votes
DPKJ
Community Champion
March 1, 2020

Here is a simplest version that I can share,

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.util.AttachmentUtils

def issueManager = ComponentAccessor.getIssueManager()
def attachmentManager = ComponentAccessor.getAttachmentManager()

def issue = issueManager.getIssueObject("<DESIRED_ISSUE_KEY"); // e.g. SP-1

def attachments = attachmentManager.getAttachments(issue)

attachments.each{ attachment ->
def fileName = attachment.fileName


def filePath = AttachmentUtils.getAttachmentFile(attachment)
def attachmentFile = new File(filePath)


}

 

Important portion here are, fetching attachment object and getting it's file path using AttachmentUtils helper class (this is because attachments are stored in file system using special directory structure)

Once you have attachment file you can use it as you wish.

Tom Lister August 15, 2020

Hi @DPKJ 

Did you get as far as reading an attachment?

Best

Tom

DPKJ
Community Champion
August 18, 2020

It worked for me when I last tried.

I will give it another trial once I get some time.

Suggest an answer

Log in or Sign up to answer