Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Get an PDF Attachment file from a Jira Issue using Groovy script in ScriptRunner

Get an PDF Attachment file from a Jira Issue using Groovy script in ScriptRunner.

I am trying to get the attachment of a Jira issue in Jira Service Management(Server) using Groovy Script under ScriptRunner plugin.

Please help me in finding the solution.

Here is the code I am using now:

1). Getting  java.lang.StackOverflowError with this code: 

List attachments = aM.getAttachments(issue)

def attachmentID;
File attachmentFile;

if (!attachments.isEmpty()) {
for (Attachment a in attachments) {
String fileName=a.getFilename()
log.warn(fileName)
attachmentID = a.getId()
log.warn(attachmentID)


String storePath=pM.getAttachmentPath()
def attachmentFilePath = new File(storePath).path
attachmentFile= new File(attachmentFilePath,fileName)
log.warn(attachmentFile)
log.warn(attachmentFile.text)
}
}

 

2). This gives NullPointer Exception as File object is coming as "null"

File file = ComponentAccessor.getComponent(FileSystemAttachmentDirectoryAccessor.class).getAttachmentDirectory(issue).listFiles().find({
File it->
it.getName().equals(attachmentID)
});

if(file.exists()){
log.warn("File exists!!!");
}else{
log.warn("NOOOOOOOOOOOOOO");
}

Not sure what I am missing.

NOTE : I am new to Jira and Groovy.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

New Cloud Apps Roundup - April 2021

Atlassian's marketplace partners have had a very productive start to 2021! Since our last roundup, our developer community has added over 160 new cloud apps to the Atlassian Marketplace to help you...

317 views 3 20
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you