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.ComponentAccessordef im = ComponentAccessor.issueManagerdef am = ComponentAccessor.attachmentManagerdef issue = im.getIssueObject('JSP-4736')am.getAttachments(issue).sort{it.created}.last()
@PD SheehanThanks Peter!
@PD 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
Correct, this question was just about sorting and retrieving that last attachment object. Nothing was mentioned about retrieving the actual file content.
@Hemanth Kumar - did you ever solve for this? Looking at doing something similar.
@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.attachmentsdef 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}
It looks like you're new here. Sign in or register to get started.