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

 

custom_email.png

 

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

http://docs.groovy-lang.org/latest/html/documentation/template-engines.html#GroovyTemplates-GStringTemplateEngine

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

This widget could not be displayed.

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

Regards

Thanos

This widget could not be displayed.

Thanos, 

 

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 

 

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(Binding.java:63) at groovy.lang.Binding.getProperty(Binding.java:105) at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:172) at groovy.lang.Closure.getPropertyTryThese(Closure.java:324) at groovy.lang.Closure.getPropertyDelegateFirst(Closure.java:314) at groovy.lang.Closure.getProperty(Closure.java:299) at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:50) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307) at groovy.tmp.templates.GStringTemplateScript53$_getTemplate_closure1.doCall(GStringTemplateScript53.groovy:25) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1019) at groovy.lang.Closure.call(Closure.java:426) at groovy.lang.Closure$WritableClosure.writeTo(Closure.java:856) at groovy.lang.Closure$WritableClosure.toString(Closure.java:982) at sun.reflect.GeneratedMethodAccessor7788.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) 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 4.2.0.4 installed

ok, so my above comments are valid. 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

484 views 3 18
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