Custom field insertion in e-mail subject (GStringTemplate)

I'm trying to send a mail via a transition's post-function.

The subject and body fields say, you can enter GStringTemplates, but I can't find any decent documentation about that.

How do I simply insert e.g. custom field foo (id 12345) to the subject and/or body?

2 answers

1 accepted

1 vote

It's a pain doing it in the subject. You need something like this:

Issue ID: ${}, Custom Field Value: <% out << issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("My custom field")) %>

Thank you.

I'll try that, but before that I have to configure a test smtp.

You can use the "preview" function to see what the subject will look like. This is highly recommended before firing off emails.

Interesting. Where can I see the preview?

I can configure the field "Preview Issue Key" when editing the transition, but I don't see no button "Preview".

I tried with this as subject:

"Es wurde ein neues Artefakt $issue zum Deployment gemeldet. cfValues['customfield_12714']".

But it doesn't resolve the custom field and results in this subject:

"[TEST] Es wurde ein neues Artefakt LUUS-1126 zum Deployment gemeldet. cfValues['customfield_12714']"

Answer updated...

Thanks for the update. But I fear, it's still not working:

<% out << issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("customfield_12714")) %>

2013-01-16 08:33:47,003 http-8081-17 ERROR 513x22538x1 1o7xo1j, /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
	at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(
	at com.atlassian.jira.issue.Issue$ Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(
	at groovy.tmp.templates.GStringTemplateScript6$_getTemplate_closure1.doCall(GStringTemplateScript6.groovy:2)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	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 groovy.lang.Closure$WritableClosure.writeTo(
	at groovy.lang.Closure$WritableClosure.toString(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

I also tried with :

<% out << issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectById(12714)) %>


<% out << issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectById(12714L)) %>

But am getting these errors:

2013-01-16 08:51:51,617 http-8081-22 ERROR 531x22643x1 j2tplz, /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.managers.DefaultCustomFieldManager.getCustomFieldObjectById() is applicable for argument types: (java.lang.Long) values: [12714]
Possible solutions: getCustomFieldObject(java.lang.Long), getCustomFieldObjects(), getCustomFieldObject(java.lang.String), getCustomFieldObjectByName(java.lang.String), getCustomFieldObjects(com.atlassian.jira.issue.Issue), getCustomFieldObjects(

You need the name of the custom field, not the ID. The name is the name that you see when editing an issue in the UI. If you want to use the ID, change getCustomFieldObjectByName to another method.


Thank you.

BTW: I tried getCustomFieldObjectById() but it didn't work because it expects a java Long. Do you know how to specify that in Groovy? I tried without quotes and with and without L.

Use either `1 as Long` or `1L`, or `new Long(1)`, no quotes in either case.


I use the plugin script runner and use the script post-function. I use the script "Sending a custom email on a transition'. How insert the value of the custom field present in the issue in the template of the mail? How recove the value by id?


Isn't this question the same as the one you are asking? Why do you need the custom field ID? If you need it you can get it from the view custom fields page, or from the db.

Thank you. How I can to recove the name of status by groovy? I tried issue.status?.name but it doesn't work.


can you explain doesn't work. That should work but is probably better.

Thank you for the answer. I forget "$".

HI jaime,

Currently we are using jira 6.0.5

we need to display the custom field value in the subject of the email whenever the respective field is updated

the field is a version picker

currently we are using the text mode for email notification.i have edited the issueupdated.vm.i have tried the below template

# if the custom field value is empty print the issuekey.issuetype,and summary else print issuekey,updated custom field value and issue summary

if($issue.getCustomFieldValue("customfield_1001") = "")

($issue.key) ($ $issue.summary

($issue.key) $issue.getCustomFieldValue("customfield_1001") ($ $issue.summary

im not getting the value when the custom field is updated.

please help me with valid template

that's a velocity template, not related to my plugin

Suggest an answer

Log in or Join to answer
Community showcase
Alexey Matveev
Published Saturday in Jira

How to run Jira in a docker container

Everything below is tested on Ubuntu 17.10. I prefer to use Jira in a docker container because: 1. I can install Jira with a couple of commands. 2. I can start and stop Jira just by starting and s...

384 views 6 8
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot