Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,360,262
Community Members
 
Community Events
168
Community Groups

ScriptRunner - add currently new attachments to mail via listner

hello,

 

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("dieter@home.at"); 
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"; java.io.File csvFile = new java.io.File("/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);
Like Kiran Jonnada likes this

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
TAGS
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

190 views 1 6
Read article

Atlassian Community Events