Access the full Jira API from email templates

Email templates in Email this issue may be customized easily using HTML and Apache Velocity scripting engine. Sometimes you need to access data in Jira that is not explicitly accessible via issue fields and custom fields.

Email This Issue makes the whole Jira API accessible to you.

ComponentAccessor - Access the Jira API

The starting point to access the Jira API is the ComponentAccessor referenced as $componentAccessor. It has lots of methods to access Manager components directly or indirectly. 

Example: Render an Issue's Remote Links in Emails

Remote links in a Jira issue may be web links or Confluence page links. The solution takes a few steps 

  1. Create a reusable Velocity macro (line 1)
  2. Get reference to the API component you need (lines 2,3)
  3. Load the data you want to render (lines 4 through 7)
  4. Call the macro to render complex content
 #macro (renderRemoteLinks $issue)
  #set($remoteLinkManagerClass = $!componentAccessor.getClass().getClassLoader().loadClass("com.atlassian.jira.issue.link.RemoteIssueLinkManager"))
  #set($remoteIssueLinkManager = $!componentAccessor.getComponentOfType($remoteLinkManagerClass))
  #set($remoteLinks = $!remoteIssueLinkManager.getRemoteIssueLinksForIssue($!issue))
  #foreach($remoteLink in $!remoteLinks)
  #if($velocityCount > 1), #end<a href="$!remoteLink.url">$!remoteLink.title</a>
  #end
#end


You'll need to study the Jira API documentation to understand which managers to call and how to render the objects the API returns.

Be careful to call API methods that modify data. The safe use of data modification API requires experience to avoid data loss.

Data query API like above however is safe to use in the templates.