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

This widget could not be displayed.

http://groovy.codehaus.org/api/groovy/text/GStringTemplateEngine.html

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

Issue ID: ${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 nabil.sayegh@example.com 513x22538x1 1o7xo1j 10.109.54.241,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
java.lang.NullPointerException
	at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:938)
	at com.atlassian.jira.issue.Issue$getCustomFieldValue.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
	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(CachedMethod.java:90)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:884)
	at groovy.lang.Closure.call(Closure.java:412)
	at groovy.lang.Closure$WritableClosure.writeTo(Closure.java:828)
	at groovy.lang.Closure$WritableClosure.toString(Closure.java:954)
	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)) %>

and

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

But am getting these errors:

2013-01-16 08:51:51,617 http-8081-22 ERROR nabil.sayegh@example.com 531x22643x1 j2tplz 10.109.54.241,127.0.0.1 /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(com.atlassian.jira.issue.search.SearchContext)

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.

Works!

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.

This widget could not be displayed.

Hello,

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?

Guis

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.

Guis

can you explain doesn't work. That should work but issue.statusObject.name 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.issueTypeObject.name) $issue.summary

#else
($issue.key) $issue.getCustomFieldValue("customfield_1001") ($issue.issueTypeObject.name) $issue.summary
#end

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 Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

135 views 2 0
Join discussion

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