Adding Custom Fields to Email

This tutorial shows you how to print a custom field in an email. Note, there is an open feature request to integrate this into JIRA, which is tracked here: JRA-4619.

1. Find the Custom Field ID

The Custom Field ID can be discovered from the database or by examining the URLs of custom field pages.

To find the Custom Field ID by examining the URL of a custom field page:

  1. Navigate to the Custom Field configuration in the JIRA administration console, as described on  Configuring a Custom Field.
  2. Click the cog icon to display the menu for the custom field.
  3. Hover your mouse over the Configure item in the menu. The URL will display in the footer of your browser. The URL will show the Custom Field ID.

For example, in this screenshot, the ID of the custom field is 10000:

To find the Custom Field ID by querying the database:

Run the following query on your database:

query

SELECT * FROM customfield WHERE cfname LIKE '%mycustomfield%';

 where 'mycustomfield' is your custom field name.

2. Edit the velocity template

If using the EAR/WAR version, make changes in the edit-webapp directory, then rebuild and re-deploy the WAR file.

Locate the Velocity template of the email type you wish to modify. For instance, you may want to modify the 'issue created' template, as well as the template reused in 'issue commented':

atlassian-jira/WEB-INF/classes/templates/email/text/issuecreated.vm
atlassian-jira/WEB-INF/classes/templates/email/text/includes/issuesummary.vm

Add the following snippet where you want it to appear in the file:

#if ($issue.getCustomFieldValue("customfield_10000"))
$stringUtils.leftPad($issue.getCustomField("customfield_10000").name, $padSize): $issue.getCustomFieldValue("customfield_10000")
#end

The javadoc for $stringUtils.leftPad can be found here: StringUtils.

In atlassian-jira/WEB-INF/classes/templates/email/text/includes/issuesummary.vm you will want:

#if ($issue.getCustomFieldValue("customfield_10000"))
>$stringUtils.leftPad($issue.getCustomField("customfield_10000").name, $padSize): $issue.getCustomFieldValue("customfield_10000")
#end

Note: you need to change the custom field id to the id observed in step 1. Here it is 10000 - yours will probably be different.

If you wish to iterate over all related custom fields you can use the following example:

#foreach ($value in $customFieldManager.getCustomFieldObjects($issue))
>$stringUtils.leftPad($value.getName(), $padSize): $!value.getValueFromIssue($issue)
#end

3. Restart JIRA

To make the changes take effect, restart JIRA. If you wish to avoid the continual restarts during testing, edit atlassian-jira/WEB-INF/classes/velocity.properties and alter this section as the comment says:

# To enable autoreloading, set cache to false and uncomment the autoreload line
class.resource.loader.cache=true
#velocimacro.library.autoreload=true
Was this page helpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport