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
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.