Custom field in E-mail subject

Christian Czaia _Decadis AG_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2013

Hey,

I've been looking around but I can't get waht I want. I want a custom field (number field) shown in my email subject.

According to those posts:

https://confluence.atlassian.com/display/JIRA/Customising+Email+Content

https://developer.atlassian.com/display/JIRADEV/Adding%20Custom%20Fields%20to%20Email

https://answers.atlassian.com/questions/115392/jira-email-notification-subject-adjustments

https://answers.atlassian.com/questions/69875/adding-a-custom-field-to-the-automated-jira-generated-email

I have edited the issuecreated.vm in the subject folder. That's what I have:

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

Watching the mail queue it seems like it should be working (cf is shown) but the logs show me the following error:

2013-05-14 12:57:07,764 http-8090-6 WARN CzaiaC 777x546x1 zs956v 10.250.205.193 /secure/admin/MailQueueAdmin!default.jspa [velocity] org.apache.velocity.runtime.exception.ReferenceException: reference : template = getEncodedBodyFromContent [line 1,column 14] : $issue.getCustomFieldValue("customfield_12562") is not a valid reference.
	at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:277)

Any ideas?

1 answer

1 accepted

1 vote
Answer accepted
Chaithra N
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2013

Hi,

Use as below

#set($cField=$customFieldManager.getCustomFieldObject("customfield_12562"))

$issue.getCustomFieldValue($cField)

Christian Czaia _Decadis AG_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2013

I'll try it.

Christian Czaia _Decadis AG_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2013

Strange... The subject seems to be correct if you look at the mail queue but as soon as the mail gets sent, the subject is empty (apart from the configured prefix)

Chaithra N
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 14, 2013

Are you still having the issues, even after using the above code.

Also in the error list which you have shared it states that $issue.getCustomFieldValue("customfield_12562") is not a valid reference.

Because issue.getCustomFieldValue(X), will take customfield & since you were not passing the Customfield you were getting error.

Also please check if the value returned is not null before using it in summary

Christian Czaia _Decadis AG_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 14, 2013

Yes, the value is not null and I don't get an error in the logs now. The subject of the mail is just empty now...

Do I have to edit any other fields than issuecreated.vm in the subject folder?

Chaithra N
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 16, 2013

Hi,

I have tried similar kind in the mail subject & it is working perfectly fine.

looks like there is some other problem in your case.

Christian Czaia _Decadis AG_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 23, 2013

I'm getting closer now:-) My next problem is, that my custom field is a number field (57670.0) but representing not a real number, more like a request number. Do you have any ideas how to get rid of the decimals to show only 57670?

Chaithra N
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 23, 2013

You can use string split function, convert value to string (i.e .toString()) and then split it based on "." and then use the result accordingly

Christian Czaia _Decadis AG_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 26, 2013

I used the longValue() method:

#set($cFieldValue=$issue.getCustomFieldValue($cField).longValue().toString())

Suggest an answer

Log in or Sign up to answer