Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner - add currently new attachments to mail via listner

congo bongo January 29, 2018

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...

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Nitinraj September 15, 2023

Hello @congo bongo ,

Are you able to find the solution? I am also stuck in the same.

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 29, 2018

I think the problem is with

{MailAttachment a -> ${it.filename}

What are you trying to do with the line?

congo bongo January 30, 2018

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

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2018

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
congo bongo January 30, 2018

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))

congo bongo February 1, 2018

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

TAGS
AUG Leaders

Atlassian Community Events