You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi
I need to get from the issue last added attachment. Do you know how I can achieve this? I'm able to get list of issue attachemnts but this list is sorted by name.
Regards,
Seba
Just sort the attachment collection by created attribute:
import com.atlassian.jira.component.ComponentAccessor
def im = ComponentAccessor.issueManager
def am = ComponentAccessor.attachmentManager
def issue = im.getIssueObject('JSP-4736')
am.getAttachments(issue).sort{it.created}.last()
@Peter-Dave SheehanThanks Peter!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Peter-Dave Sheehan thanks for the answer, i am figuring a way to sort the attachments (irrespective of file format) and attach to the email notification as part of script runner post function. Kindly assist me.
In your above method seems like its just sorting but not fetching the latest file ?
I found below method but couldn't derive for all format:
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(".pdf")
it.filename.endsWith(".jpg")
it.filename.endsWith(".png")
it.filename.endsWith(".xlsx")
}.sort { it.created }.last()
return latest.id == a.id
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Correct, this question was just about sorting and retrieving that last attachment object. Nothing was mentioned about retrieving the actual file content.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Peter-Dave Sheehan thanks for the response. As requested above, I am figuring a way to sort the attachments (irrespective of file format) and attach to the email notification as part of script runner post function. Please assist me with this.
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.
@Esabel Gomez Yes, i was able to solve with below scripts
My requirement was to fetch latest comments and attachment and respond to user via mail that issue is closed successfully.
<< Below section is for fetching latest attachment irrespective of file formats >>
import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.mail.MailAttachment
{
MailAttachment a ->
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
}
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.