Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

How to find latest attachment in an jira issue and attach to the email notification

I am using email this issue script runner post function. I need to find last/latest attachment in an issue and email that as part of closure notification. I found below script and its working for pdf format, but i tried deriving for all format but it couldn't.

Can any one help ?

----------------

import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.mail.MailAttachment
{
MailAttachment a ->

def issue = a.issue

def allAttachments = issue.attachments

def latest = allAttachments.findAll {

it.filename.endsWith(".docx")
it.filename.endsWith(".jpg")
it.filename.endsWith(".png")
it.filename.endsWith(".xlsx")

it.filename.endsWith(".pdf")

}.sort { it.created }.last()

return latest.id == a.id

2 answers

1 accepted

1 vote
Answer accepted

My requirement was to fetch issue details, latest comments and latest attachment and send a closure notification to the issue filed "email". With help of Ram Kumar (atlassian admin) was able to fetch few helps and i finally composed a complete solution.

I have used Script runner (email this issue) post function.

 

Custom attachment callback: (to fetch latest comments in listed formats)

mport com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.mail.MailAttachment
{
MailAttachment a ->
def issue = a.issue
def issue a.issue
def allAttachments = issue.attachments
def fileExtensions = ['.pdf', '.jpg', '.jpeg', '.docx', '.xlsx', '.png']
def latest = allAttachments.findAll {
fileExtensions.each { String fileType ->
it.filename.endsWith(fileType)
}
}.sort { it.created }.last()
return latest.id == a.id
}

But when i use this along with my other template and try completing the ticket - its throwing an error. 

Done-Transitions.JPG

i am using Email Issue Post-function  where i have configured subject, HTML Body and under attachment options chosen - Attachments returned by a Groovy script as shown below. Kindly advise where i made a mistake.

attachment groovy.JPG

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events