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...
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"
}
}
}
Thanks, this helped me get to where I wanted to go.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.