Email responses with Issue field content

Trying to send a custom email to reporter upon Issue creation (issue created within Service Desk) which includes some details about the values they entered for various fields (including custom fields) within the Body of the email...  (see example of what I am effectively wanting to do below)...  So trying to do this via a script that would fire on issue creation,  (with ScriptRunner)...  




so wondering if there is a trick to this simply or do I have to look at the GStringTemplateEngine... that is suggested on that config page...

and if so...

curious how I get to my specific JIRA fields "standard" and custom fields. like issue, description, (some custom field...)

appreciate any real life example for JIRA that I can use...
(that GStringTemplateEngine wiki doesn't help me to know how to get at JIRA field...) 

Appreciate any suggestions.

2 answers

Hi Dave

I think the example below covers a couple of cases (issue fields, subtasks, custom fields). Hope is enough for a start, if you want something that is not covered from the example, comment and I can assist further (I suppose you already know how to set up a listener, and your question was mainly for the email body).  

def issueTypeName = issue.issueType?.name
def issuePriority = issue.priority?.name
def subTaskList = issue.getSubTaskObjects()
def firstSubTask = subTaskList ? subTaskList[0] : null
def subTaskId = firstSubTask?.getId()
def subtaskPriority = firstSubTask?.priority?.name
def subTaskType = firstSubTask?.issueType?.name
def subTaskCustomField = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName
("A custom field name")
def customFieldValue = firstSubTask?.getCustomFieldValue(subTaskCustomField)
Issue Name: $issue <br>
Issue typeName: $issueTypeName <br>
Issue priority: $issuePriority <br>
Subtask Name: $firstSubTask <br>
SubtaskId: $subTaskId <br>
Subtask Priority: $subtaskPriority <br>
Subtask Issue type: $subTaskType <br>
Subtask url: <a href="$baseUrl/browse/<% out << firstSubTask?.key %>">$firstSubTask</a> <br>
$subTaskCustomField (customField): $customFieldValue





thank you for the advice.   Well it is my first "attempt" so I'm falling over simple steps I fear,

So in trying to create an easy "listener",  - send a custom email,

I put just these 2 lines in the email template portion of that "listener"

def CustomFieldSelectedAreas = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Selected Areas")
def SelectedAreas = issue.getCustomFieldValue(CustomFieldSelectedAreas)


but get this type error 



No such property: componentManager for class: groovy.lang.Binding

groovy.lang.MissingPropertyException: No such property: componentManager for class: groovy.lang.Binding at groovy.lang.Binding.getVariable( at groovy.lang.Binding.getProperty( at org.codehaus.groovy.runtime.InvokerHelper.getProperty( at groovy.lang.Closure.getPropertyTryThese( at groovy.lang.Closure.getPropertyDelegateFirst( at groovy.lang.Closure.getProperty( at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty( at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty( at groovy.tmp.templates.GStringTemplateScript53$_getTemplate_closure1.doCall(GStringTemplateScript53.groovy:25) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke( at sun.reflect.DelegatingMethodAccessorImpl.invoke( at java.lang.reflect.Method.invoke( at org.codehaus.groovy.reflection.CachedMethod.invoke( at groovy.lang.MetaMethod.doMethodInvoke( at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod( at groovy.lang.MetaClassImpl.invokeMethod( at at groovy.lang.Closure$WritableClosure.writeTo( at groovy.lang.Closure$WritableClosure.toString( at sun.reflect.GeneratedMethodAccessor7788.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke( at java.lang.reflect.Method.invoke( at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke( at at at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail$_getDescription_closure15$_closure26$_closure34.doCall(SendCustomEmail.groovy:669) at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail$_getDescription_closure15$_closure26$_closure34.doCall(SendCustomEmail.groovy
I am doing this on JIRA 7.0.4...  wondering if this is a JIRA 7
I also just tried to create a custom listener  and rather than use the custom email option...
but I ran into trouble there too. again I bet its something silly... I've attached a screen shot of that...custom_listener.png

Hi Dave,

For the first error you get, you use somewhere the componentManager which in JIRA version 7 onwards became deprecated. Use componentAccessor instead (in the way you did in the lines you pasted).

For your second question. In a custom listener the only think that is bind is the event. Therefore in order to get the issue you should 

def myIssue = event.issue

hmmm you said you use JIRA v7.0.4 so the next question is which SR version you use ?

we have installed

ok, so my above comments are valid. 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

441 views 8 26
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you