Velocity Context in Email Rendering

Email templates are velocity macro files. When email templates are used to render email body, the following Velocity context attributes are available.

Template Context Objects

Name
Type
Description
attachmentsManagercom.atlassian.jira.mail.util.MailAttachmentsManagerManager component
baseurlStringBase url of the Jira instance, set under General Configuration
buildutilscom.atlassian.jira.util.BuildUtils
customfieldManagercom.atlassian.jira.issue.CustomFieldManagerSupport for adding custom fields to outgoing emails
dateformattercom.atlassian.jira.web.util.OutlookDateDate format support
issuecom.atlassian.jira.mail.TemplateIssueIssue extended with support for processing in velocity templates
i18ncom.atlassian.jira.util.I18nHelperI18n support
jirakeyutilscom.atlassian.jira.util.JiraKeyUtils
jirautilscom.atlassian.jira.util.JiraUtils
remoteUsercom.atlassian.jira.user.ApplicationUserCurrent user running the action or null
rendererManagercom.atlassian.jira.issue.RendererManager
stringUtilsorg.apache.commons.lang.StringUtilsString helper methods
textutilscom.opensymphony.util.TextUtilsJira's text util methods
userutilscom.atlassian.core.user.UserUtils
jetiFieldRendererSee belowSupport for field rendering in templates. See details below.
jetiFieldFormatterSee belowSupport for date/time formatting in templates. See details below.
templateSupportSee belowSupport for email templates, rendering, formatting. See details below.
numbercom.atlassian.jira.util.velocity.NumbertoolSupport for Number formatting in templates. See API documentation
currentUserInfo

$!currentUserInfo.user: current user object
$!currentUserInfo.roles: current user's project roles
$!currentUserInfo.groups: current user's groups.

userPropertyManager
 com.atlassian.jira.user.UserPropertyManager

 Access to Jira user properties. .

Usage:

Refernces to user properties by property name must be prefixed with "jira.meta." due to the nature of the Jira API.

E.g. If the user has a property, called "phone", the phone property may be rendered as

$!userPropertyManager.getPropertySet(<user object>).getString("jira.meta.phone")

currentTimestampjava.util.Date Date and time of rendering the template, this like "now". 
jiraDurationUtilscom.atlassian.jira.util.JiraDurationUtilsUtil class responsible for printing durations in various formats.
diffutilscom.atlassian.jira.mail.DiffUtilsCompares two string values and renders wiki markup diffs.
isJIRA610OrLaterbooleanDetermines whenever the currently installed Jira version is at least 6.1.0
datetimeformattercom.atlassian.jira.datetime.DateTimeFormatterDate-time format support
timeSpentFieldIdString

The ID of the issue's time spent field

padSizeIntegerDefault padding size for templates (20)
lfbeancom.atlassian.jira.config.properties.LookAndFeelBeanSupport for accessing Jira's look and feel parameters

menuTextHighlightColour

StringJira's menu text highlight color

textHighlightColour

StringJira's text highlight color

jiraLogoUrl

StringURL that points to Jira's logo image
topBackgroundColourStringJira's top bar background-color
topTxtColourStringJira's top bar text color
topHighlightColorStringJira's top bar highlight color
topTextHighlightColorStringJira's top bar text highlight color
topSeparatorBackgroundColorStringJira's top bar separator background-color
menuTxtColourStringJira's menu text color
menuBackgroundColourStringJira's menu background-color
menuSeparatorColourStringJira's menu separator color
textHeadingColourStringJira's header text color
textLinkColourStringJira's link text color
textActiveLinkColourStringJira's active link text color
textFontFamilyStringJira's text font
textSizeStringJira's text size
textColourStringJira's text color
textSubtleColourStringJira's subtle text color
borderColourStringJira's border color
auiPanelBackgroundColourString

Atlassian User Interface's panel background color

auiPanelBorderColourStringAtlassian User Interface's panel border color
auiInfoBackgroundColourStringAtlassian User Interface's info panel background color
auiInfoBorderColourStringAtlassian User Interface's info panel border color
auiSuccessBackgroundColourStringAtlassian User Interface's success panel background color
auiSuccessBorderColourStringAtlassian User Interface's success panel border color
auiErrorBackgroundColourStringAtlassian User Interface's error panel background color
auiErrorBorderColourStringAtlassian User Interface's error panel border color
auiWarningBackgroundColourStringAtlassian User Interface's warning panel background color
auiWarningBorderColourStringAtlassian User Interface's warning panel border color
linkstyleStringComment author link style
commentBackgroundlStringComment quotes color

jetiFieldRenderer

jetiFieldRenderer provides a lot of useful methods to render issue fields

MethodDescriptionUsage
String renderCustomField(Issue issue, String fieldKey);
Renders a custom field value as a string value$!jetiFieldRenderer.renderCustomField($!issue, "customfield_10011")
Object renderCustomFieldAsObject(Issue issue, String fieldKey);

Returns the value of the custom field as Raw value.

The Raw or Object value allows for further processing or access to methods, and attribues

$!jetiFieldRenderer.renderCustomFieldAsObject($!issue, "customfield_10011")

E.g. render the Display name attribute of a user selected in a user picker field

$!jetiFieldRenderer.renderCustomFieldAsObject($!issue, "customfield_10011").getDisplayName()

String renderVersions(Collection<Version> versions);
Renders the given versions as a comma-separated list of version names.E.g. $!jetiFieldRenderer.renderVersions($!issue.getFixVersions())
String renderComponents(Collection<ProjectComponent> components);
Renders the given components as a comma-separated list of component names.E.g. $!jetiFieldRenderer.renderComponents($!issue.getComponents())
String renderLabels(Collection<Label> labels);
Renders the given labels as a comma-separated list of label names.E.g. $!jetiFieldRenderer.renderLabels($!issue.getLabels())
String renderSecurityLevel(GenericValue securityLevel);
Renders the name of the given Security Level object $!jetiFieldRenderer.renderSecurityLevel($!issue.getSecurityLevel())
String renderIssueConstant(IssueConstant issueConstant);
Renders the name of an Issue type, Resolution, Priority or Status$!jetiFieldRenderer.renderIssueConstant($!issue.getPriority())
String renderUser(User user);
Renders the DisplayName attribute of a User or Application User object safely, if null, returns empty string$!jetiFieldRenderer.renderUser($!issue.getAssignee())
String renderDateTime(Timestamp ts);
Renders a Timestamp object using Jira's default date format, DateTimeFormat.format()

E.g.

  • $!jetiFieldRenderer.renderDateTime($!issue.getCreated())
  • render the value of a date or date time picker field: $!jetiFieldRenderer.renderDateTime($!jetiFieldRenderer.renderCustomFieldAsObject($!issue, "customfield_10011"))
String renderEstimate(TemplateIssue ti, I18nHelper i18n);
Renders the issue's Original estimate in nicely readable format, like 3d 4h 5m$!jetiFieldRenderer.renderEstimate($!issue, $i18n)
String renderRemainingEstimate(TemplateIssue ti, I18nHelper i18n);
Renders the issue's Remaining estimate in nicely readable format, like 3d 4h 5m$!jetiFieldRenderer.renderOriginalEstimate($!issue, $i18n)
String renderWorklog(TemplateIssue ti, I18nHelper i18n);
Renders the issue's Logged Work Time in nicely readable format, like 3d 4h 5m$!jetiFieldRenderer.renderWorklog($!issue, $i18n)
I18nHelper getI18nBean(String locale);

Returns a I18nBean for the given locale, locale string follows java syntax

E.g. get the language resources for French: $!jetiFieldRenderer.getI18nBean("fr")
String getLinkToCustomerPortal(Issue issue);

Returns an absolute link to the customer portal belonging to the service management project of the issue.

If the issue is not from a Service Management project, it returns null

$!jetiFieldRenderer.getLinkToCustomerPortal($!issue)
String getLinkToIssueInCustomerPortal(Issue issue);

Returns an absolute link to the issue in the customer portal belonging to the service management project of the issue.

If the issue is not from a Service Management project, it returns null

$!jetiFieldRenderer.getLinkToIssueInCustomerPortal
($!issue)


jetiFieldFormatter

jetiFieldFormatter is an object in the template context that may be used to format date or date time values.

It provides the below methods:

MethodDescriptionUsage
DateTimeFormatter getJiraDateTimeFormatter()
Returns a native Jira DateTimeFormatter object#set ($formatter = $jetiFieldFormatter.getJiraDateTimeFormatter())
DateTimeFormatter getJiraDateTimeFormatter(String style)Returns a native Jira DateTimeFormatter object configured with DateTimeStyle provided#set ($formatter = $jetiFieldFormatter.getJiraDateTimeFormatter("COMPLETE"))
DateFormat getJavaDateFormat()
Returns a Java DateFormat object for date formatting#set ($formatter = $jetiFieldFormatter.getJavaDateFormat())
DateFormat getJavaDateFormat(int style)
Returns a Java DateFormat object configured with the value of the style constants (see java documentation)
DateFormat getJavaDateFormat(int style, String locale)

Returns a Java DateFormat object configured with the value of the style constants (see java documentation) and a locale.

Example for locales: en, en_US, fr, de, see more examples in the documentation
DateFormat getJavaDateTimeFormat()
Returns a Java DateFormat object for date time formatting
DateFormat getJavaDateTimeFormat(int dateStyle, int timeStyle)
Returns a Java DateFormat object for date time formatting configured with the value of the style constants (see java documentation)
DateFormat getJavaDateTimeFormat(int dateStyle, int timeStyle, String locale)
Returns a Java DateFormat object for date time formatting configured with the value of the style constants (see java documentation) and a locale.
DateFormat getJavaDateTimeFormat(String pattern)
Returns a Java SimpleDateFormat object for date time formatting configured with a pattern#set($formatter = $jetiFieldFormatter.getJavaDateTimeFormat("dd/MM/yyyy HH:mm"))
String formatSafely(DateFormat formatter , Date value)
Formats a date value using the formatter created using either of the above methods

$!jetiFieldFormatter.formatSafely($!formatter, $issue.updated)

or

$!jetiFieldFormatter.formatSafely($!formatter, $issue.getCustomFieldValue("customfield_12345"))

TimeZone getTimeZone(String tzID)
Returns the TimeZone matching the id. TimeZone can be set in the Java date time formatters created above$!formatter.setTimeZone($jetiFieldFormatter.getTimeZone("America/Los_Angeles"))
TimeZone getDefaultTimeZone()
Returns the default TimeZone in Jira.
String[] getAvailableTimeZoneIDs()
Returns all time zone IDs available in Jira.


templateSupport

MethodDescriptionUsage
String encodeUrl(String url);
Calls URLEncoder.encode(url) to encode rendered URLs in email templates using UTF-8 encoding$!templateSupport.encodeUrl($urlVariable)
String encodeUrl(String url, String encoding);Calls URLEncoder.encode(url, encoding) to encode rendered URLs in email templates using the encoding specified$!templateSupport.encodeUrl($urlVariable, <desired encoding>)
Issue firstIssueMatchingJQL(String jql);Returns the first issue that matches the given JQL query
#set($firtstIssue = $!templateSupport.firstIssueMatchingJQL("project = $issue.projectObject.key AND assignee=$!currentUser.name AND priority = Highest"))

$!firstIssue.summary
TemplateIssueSearchResults searchForIssuesByJQL(String jql);Returns a list of issues matching the given JQL query
#set($searchResults = $!templateSupport.searchForIssuesByJQL("project=IT AND resolution=Unresolved", 10))
  #foreach($result in $searchResults.getResults())
$velocityCount - $!result.key (comments: $!result.comments.size())
  #end
TemplateIssueSearchResults searchForIssuesByJQL(String jql, int maxresults);Same as above but limits the results to the given number of issues
boolean issueMatchesJQL(String jqlQuery, Issue issue);Checks if the given issue matches the JQL query
#if($!templateSupport.issueMatchesJQL("mycustomfield = somevalue AND component=ImportantComponent", $!issue) 
## do something...
#end
Locale getLocale(String localeName);

Creates a Java Locale object to be used in date / number formatting or language support.

Local name is composed of language code and country code.

e.g. "fr" is for french language, while "fr_FR" is the french spoken in France.

#set($frenchLocale = $!templateSupport.getLocale("fr_FR")
I18nHelper getI18nHelper(String localeName);

Create an I18nHelper object for the locale

Local name is composed of language code and country code.

e.g. "fr" is for french language, while "fr_FR" is the french spoken in France.

#set($i18nFrench = $!templateSupport.getI18nHelper("fr_FR")	
I18nHelper getI18nHelper(Locale locale);

Create an I18nHelper object for the locale

Local name is composed of language code and country code.

e.g. "fr" is for french language, while "fr_FR" is the french spoken in France.

#set($frenchLocale = $!templateSupport.getLocale("fr_FR")
#set($i18nFrench = $!templateSupport.getI18nHelper($frenchLocale)	
boolean isAgent(ApplicationUser applicationUser, Project project);Determines if the given use is an Service Management Agent in the given project
#if($!templateSupport.isAgent($!issue.reporter, $!issue.projectObject)
...
#end
String getParentValueFromCascadingSelectFieldValue(Map cascadeSelectFieldValue);
String getChildValueFromCascadingSelectFieldValue(Map cascadeSelectFieldValue);
Returns the parent or child value of a Cascade Select custom field.
#set($parentValue = $!templateSupport.getParentValueFromCascadingSelectFieldValue($!issue.getCustomFieldValue("customfield_12345"))

#set($childValue = $!templateSupport.getChildValueFromCascadingSelectFieldValue($!issue.getCustomFieldValue("customfield_12345"))

customfield_12345 is the key of a cascade select field

boolean isInternalComment(Comment comment);Determins if the give comment is an Service Management Internal comment in the current issue.
#if($!templateSupport.isInternalComment($!comment)) 
...
#end
String getCustomerVisibleStatus(Issue issue);Returns the Customer Visible Status name of the issue in a Service Management project#set($!customerVisibleStatus = $!templateSupport.getCustomerVisibleStatus($!issue)
String getCurrentUsersTimeZoneId()Returns  the time zone id set in the current user’s profileThe issue was updated at #renderDateTime($!issue.updated "yyyy-MM-dd'T'HH:mmZ'['z']'" $!templateSupport.currentUsersTimeZoneId)
Please note that the capital letter T in the above code is just a placeholder, an example to mark that after the date, the time value comes next.


Template macros

Macro signatureParametersDescriptionExample

#escapeHtml($value)

  • $value: the value with HTML that should be escaped
Escapes the HTML in a given value, therefore it will be displayed as text.#escapeHtml("<p>Sample html</p>")

#renderVersions($versions)

  • $versions: the list of versions to render
Renders the versions.

#renderVersions($!issue.fixVersions)

#renderComments($issue)
  • $issue: the issue whose comments are to be rendered
Renders the public comments of the issue.#renderComments($!issue)
#renderCommentsInReverseOrder($issue)
  • $comments: the issue whose comments are to be rendered
Renders the public comments os the issue in reverse order.#renderCommentsInReverseOrder($!issue)

#renderCurrentCommentIfPublic()


Renders the current comment if it is public.#renderCurrentCommentIfPublic()

#renderServiceDeskPublicComments($issue)

  • $issue: the issue whose comments are to be rendered
Renders the public comments of the issue.#renderServiceDeskPublicComments($!issue)

#renderServiceDeskInternalComments($issue)

  • $issue: the issue whose comments are to be rendered
Renders the internal comments of the issue.#renderServiceDeskInternalComments($!issue)

#renderAllComments($issue)

  • $issue: the issue whose comments are to be rendered
Renders both public and internal comments of the issue.#renderAllComments($!issue)

#renderLastComment($issue)

  • $issue: the issue whose last comment is to be rendered
Renders the last comment of the issue.#renderLastComment($!issue)

#renderCurrentComment()


Renders the current comment.#renderCurrentComment()

#renderComment()


Renders the current comment.#renderComment()

#renderComponents($issue)

  • $issue: the issue whose components are to be rendered
Renders the components of the issue.#renderComponents($!issue)

#renderDateTime($dateTimeValue $pattern $timezoneId)

  • $dateTimeValue: the value to be formatted
  • $pattern: the pattern describing the date and time format. You can find description about formatting and patterns here
  • $timezoneId: the time zone used for formatting. You can find a list in the Supported Time Zones Appendix
Formats a date-time field based on the pattern and the timezone.#renderDateTime($!issue.created "dd MMM yyyy hh:mm a" "Australia/West")
#renderDate($dateValue $pattern $timezoneId)
  • $dateValue: the value to be formatted
  • $pattern: the pattern describing the date format. You can find description about formatting and patterns here
  • $timezoneId: the time zone used for formatting. You can find a list in the Supported Time Zones Appendix
Formats a date field based on the pattern and the timezone.#renderDate($!issue.created "dd MMM yyyy" "Australia/West")

#renderLabels($issue)

  • $issue: the issue whose labels are to be rendered
Renders the labels of the issue.#renderLabels($!issue)

#renderList($listitems)

  • $listitems: the list of items to be rendered
Renders the items into a bullet list.

#renderList($!issue.affectedVersions)

#renderFlatList($listitems)

  • $listitems: the list of items to be rendered
Renders the items into a comma-separated list.#renderFlatList($!issue.affectedVersions)

#renderProject($issue)

  • $issue: the issue whose project name is to be rendered
Renders the project name of the issue.#renderProject($!issue)

#renderDescription($issue)

  • $issue: the issue whose description is to be rendered
Renders the description of the issue.#renderDescription($!issue)

#renderEnvironment($issue)

  • $issue: the issue whose Environment field is to be rendered
Renders the value of the Environment field from the issue.#renderEnvironment($!issue)

#renderIssueType($issue)

  • $issue: the issue whose type is to be rendered
Renders the type of the issue.#renderIssueType($!issue)

#renderCustomerVisibleStatus($issue)

  • $issue: the issue whose status is to be rendered
Renders the status of the issue that is visible to the customer.#renderCustomerVisibleStatus($!issue)

#renderStatus($issue)

  • $issue: the issue whose status is to be rendered
Renders the status of the issue.#renderStatus($!issue)

#renderPriority($issue)

  • $issue: the issue whose priority is to be rendered
Renders the priority of the issue.#renderPriority($!issue)

#renderResolution($issue)

  • $issue: the issue whose resolution is to be rendered
Renders the resolution of the issue.#renderResolution($!issue)

#renderIssueConstant($issueConstant)

  • $issueConstant: the value of an issue system field
Renders the value of the issue system field.

#renderIssueConstant($!issue.status)

#renderOriginalEstimate($issue)

  • $issue: the issue whose original estimate is to be rendered
Renders the original estimate of the issue.#renderOriginalEstimate($!issue)

#renderRemainingEstimate($issue)

  • $issue: the issue whose remaining estimate is to be rendered
Renders the remaining estimate of the issue.#renderOriginalEstimate($!issue)

#renderTimeSpent($issue)

  • $issue: the issue whose time spent is to be rendered
Renders the time spent field value.#renderOriginalEstimate($!issue)

#renderSummary($issue)

  • $issue: the issue whose summary is to be rendered
Renders the summary of the issue.#renderSummary($!issue)

#renderUser($user)

  • $user: the user to be rendered
Renders the user.

#renderUser($!issue.assignee)

#renderCommentBody($commentObject)
  • $commentObject: the comment whose body is to be rendered
Renders the body of a comment.#renderCommentBody($!comment)

#renderTextWithCommentRenderer($textToRender)

  • $textToRender: the text that should be rendered
Renders the given text with the comment renderer.

#renderTextWithCommentRenderer($!worklog.comment)

#renderCustomField($issue $customFieldKey)

  • $issue: the issue whose custom field is to be rendered
  • $customFieldKey: the key of the custom field
Renders the value of a custom field.#renderCustomField($!issue "customfield_10006")

#renderAllCustomFields($issue)

  • $issue: the issue whose custom fields are to be rendered
Renders the value of all custom fields on an issue.#renderAllCustomFields($!issue)

#renderWorklog($worklog)

  • $worklog: the worklog entry to be rendered
Renders a worklog entry.#renderWorklog($!issue.worklogs.get(0))

#renderWorklogs($issue)

  • $issue: the issue whose worklog entries are to be rendered
Renders all worklog entries of an issue.#renderWorklogs($!issue)

#renderUserProperty($user $propertyName)

  • $user: the user whose property is to be rendered
  • $propertyName: the name of the property to be rendered
Renders one of the user's property.#renderUserProperty($!issue.assignee "phone")

#footer()


Renders the Email This Issue footer.

#footer()

#renderLinkToCustomerPortal($issue $linkText)

  • $issue: the issue whose customer portal link is to be rendered
  • $linkText the text of the link
Renders a link to the main page of the issue's customer portal.#renderLinkToCustomerPortal($!issue "Customer Portal")

#renderLinkToIssueCustomerPortal($issue $linkText)

  • $issue: the issue whose customer portal link is to be rendered
  • $linkText the text of the link
Renders a link that points to the issue in its customer portal.#renderLinkToIssueCustomerPortal($!issue "Customer Portal")

#renderTemplate($templateId)

  • $templateId: the ID of the template to be rendered
Renders a template.#renderTemplate(1)

#renderIssueComments($order $num $restriction)

  • $order: the order in which the comments should be displayed
    Possible values:
    • empty or 'asc': the comments will be ordered by their creation date, ascending
    • 'desc': the comments will be ordered by their creation date, descending
  • $num: limit the number of comments that should be rendered
    Possible values:
    • 'all': every comment will be rendered
    • any integer: maximum the indicated number of comments will be rendered
  • $restriction: comment rendering can be restricted by the comment's visibility
  • Possible values: 
    • empty or 'none': both public and internal comments will be rendered
    • 'public': only public comments will be rendered
    • 'internal': only internal comments will be rendered
Renders the comments of an issue.#renderIssueComments("desc" 10 "all")

#renderOptOutLink($linkText)

  • $linkText: the text of the link
Renders a link that customers can use to unsubscribe from notifications.#renderOptOutLink("Unsubscribe")