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

Your Points Tracker
  • 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
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?
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

ScriptRunner - add currently new attachments to mail via listner



im trying to make a custom listener via scriptrunner, that will attach the files to the custom mail sending via scriptrunner, that i control my outgoing messages via. But after jira was updated, attachments to the issue arent loaded at the same time as the comment is commited, so the attachment wont become attached - its horrible (and im horribly bad in groovy - im more like good using perl)..


what ive achived so far is this:

import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.MailAttachment
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.attachment.TemporaryWebAttachment
import com.atlassian.jira.issue.attachment.TemporaryWebAttachmentManager
import webwork.action.ActionContext

def temporaryAttachmentUtil = ComponentAccessor.getComponent(TemporaryWebAttachmentManager)
def formToken = ActionContext.getRequest()?.getParameter(IssueFieldConstants.FORM_TOKEN)

if (formToken) {
def tempWebAttachments = temporaryAttachmentUtil.getTemporaryWebAttachmentsByFormToken(formToken)
tempWebAttachments.each { TemporaryWebAttachment it ->
log.debug "Uploaded attachment name: ${it.filename}"
{MailAttachment a -> ${it.filename}


but it doesnt compile.. can someone please tip me how to operate this groovy stuff ?


im using jira 7.5.1 and latest scriptrunner aswell - also i have servicedesk and agile - but to be hournest i wish i had nothing...

1 answer

0 votes

I think the problem is with

{MailAttachment a -> ${it.filename}

What are you trying to do with the line?

yeah i want to attach the file to the mail being generated

If you want to send a email then you would need implement something like this

Email email = new Email(""); 
email.setFrom(fromStr); email.setSubject("Hello"); email.setMimeType("text/plain"); email.setBody("Body Text"); Multipart multipart = new MimeMultipart("mixed"); MimeBodyPart attachPart = new MimeBodyPart(); String attachFile = "/tmp/SLA_Report.csv"; csvFile = new"/tmp/SLA_Report.csv"); FileDataSource source = new FileDataSource(csvFile); attachPart.setDataHandler(new DataHandler(source)); attachPart.setFileName(csvFile.getName()); multipart.addBodyPart(attachPart); email.setMultipart(multipart); SingleMailQueueItem item = new SingleMailQueueItem(email); ComponentAccessor.getMailQueue().addItem(item);

aint that over the top, when using "Send a custom email" under "script listeners" setup..?

Theres a customizable section called "Custom attachment callback" that i try and run the script in.. triggered on all transitions in a certain project that has adds a comment on any issue (then post a mail to the reporter on that comment containing any new attachments, however the build-in option for new attachments via scriptrunner doesnt work anymore, since attachments arent loading in the same transaction as the comment.. (i believe))

is there really no way to attach the new attachments into a custom email? -the embedded feature doesnt do the job..

Suggest an answer

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

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

222 views 2 1
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