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

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
3 votes
Answer accepted
PD Sheehan
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 Champions.
July 19, 2022

Your error is with 

String myVariableValue = ( String ) TeleportField .getValue()

In my experience, it's never a good idea to perform this sort of type conversion in groovy.

A multi-select field should typically return an array. If you convert that to strings, it becomes complex to process it.

Let groovy do the work for you.

def myField = getFieldById("customfield_15201")
def myFieldValue = myField.value
if(!myFieldValue){
//the field is not populated, that could be because it returns one of the followin
if(myFieldValue == null){
log.info "field is null"
}
if(myFieldValue instanceof String){
log.info "field is an empty string"
}
if(myfieldValue instanceof List){
log.info "field is an empty array" //this is the only one that should output on a multi-select field
}

} else {
if(myfieldValue instanceof List){
//bonus, if you have values in your multi-select
myFieldValue.each{selectedOption->
log.info "label of the selected option is: $selectedOption"
}
//or if you want the optionIds
myfield.formValue.each{optionId->
log.info "id of the selected option is: $optionId"
}
}
}


Daniel Steffano
Contributor
July 22, 2022

Thanks, this helped me get to where I wanted to go.

Like Deleted user likes this
TAGS
AUG Leaders

Atlassian Community Events