Velocity Context in email templates
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 |
---|---|---|
| Manager component | |
| String | The base url of the Jira instance, set under General Configuration. |
|
| |
| Support for adding custom fields to outgoing emails | |
| Date format support | |
| Issue extended with support for processing in velocity templates | |
| I18n support | |
|
| |
|
| |
| Current user running the action or null | |
|
| |
| String helper methods | |
| Jira's text util methods | |
|
| |
| See details here. | Support for field rendering in templates |
| See details here. | Support for date/time formatting in templates |
| See details here. | Support for email templates, rendering, formatting |
| Support for Number formatting in templates. See the API documentation | |
|
|
|
| Access to Jira user properties. Usage: References to user properties by property name must be prefixed with " E.g. If the user has a property, called "phone", the phone property may be rendered as
| |
| Date and time of rendering the template, this like "now". | |
| Util class responsible for printing durations in various formats. | |
| Compares two string values and renders wiki markup diffs. | |
| boolean | Determines whenever the currently installed Jira version is at least 6.1.0 |
| Date-time format support | |
| String | The ID of the issue's time spent field |
| Integer | Default padding size for templates (20) |
| Support for accessing Jira's look and feel parameters | |
| String | Jira's menu text highlight color |
| String | Jira's text highlight color |
| String | URL that points to Jira's logo image |
| String | Jira's top bar background-color |
| String | Jira's top bar text color |
| String | Jira's top bar highlight color |
| String | Jira's top bar text highlight color |
| String | Jira's top bar separator background-color |
| String | Jira's menu text color |
| String | Jira's menu background-color |
| String | Jira's menu separator color |
| String | Jira's header text color |
| String | Jira's link text color |
| String | Jira's active link text color |
| String | Jira's text font |
| String | Jira's text size |
| String | Jira's text color |
| String | Jira's subtle text color |
| String | Jira's border color |
| String | Atlassian User Interface's panel background color |
| String | Atlassian User Interface's panel border color |
| String | Atlassian User Interface's info panel background color |
| String | Atlassian User Interface's info panel border color |
| String | Atlassian User Interface's success panel background color |
| String | Atlassian User Interface's success panel border color |
| String | Atlassian User Interface's error panel background color |
| String | Atlassian User Interface's error panel border color |
| String | Atlassian User Interface's warning panel background color |
| String | Atlassian User Interface's warning panel border color |
| String | Comment author link style |
| String | Comment quotes color |
jetiFieldRenderer
jetiFieldRenderer
provides the following methods to render issue fields:
Method | Description | Usage |
---|---|---|
| Renders a custom field value as a string value |
|
| Returns the value of the custom field as Raw value. The Raw or Object value allows for further processing or access to methods, and attributes |
E.g. render the Display name attribute of a user selected in a user picker field
|
String | Renders the given versions as a comma-separated list of version names. | E.g. |
| Renders the given components as a comma-separated list of component names. | E.g. |
| Renders the given labels as a comma-separated list of label names. | E.g. |
| Renders the name of the given Security Level object | |
String re | Renders the name of an Issue type, Resolution, Priority or Status |
|
| Renders the DisplayName attribute of a User or Application User object safely, if null, returns empty string |
|
| Renders a Timestamp object using Jira's default date format, | E.g.
|
| Renders the issue's Original estimate in nicely readable format, like 3d 4h 5m |
|
| Renders the issue's Remaining estimate in nicely readable format, like 3d 4h 5m |
|
| Renders the issue's Logged Work Time in nicely readable format, like 3d 4h 5m |
|
| Returns a I18nBean for the given locale, locale string follows java syntax | E.g. get the language resources for French: |
| 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 |
|
| 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 |
|
jetiFieldFormatter
jetiFieldFormatter
is an object in the template context that may be used to format date or date time values.
It provides the following methods:
Method | Description | Usage |
---|---|---|
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. |
DateTimeFormatter is part of the Jira API
DateFormat is a standard way to format dates in Java
templateSupport
Method | Description | Usage |
---|---|---|
String | Calls URLEncoder.encode(url) to encode rendered URLs in email templates using UTF-8 encoding | $!templateSupport.encodeUrl($urlVariable) |
String | Calls URLEncoder.encode(url, encoding) to encode rendered URLs in email templates using the encoding specified | $!templateSupport.encodeUrl($urlVariable, <desired encoding>) |
boolean | Checks if the given issue matches the JQL query | #if($!templateSupport.issueMatchesJQL("mycustomfield = somevalue AND component=ImportantComponent", $!issue) ## do something... #end |
I18nHelper | 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 | 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) |
Locale | 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 the French language, while "fr_FR" is the French spoken in France. | #set($frenchLocale = $!templateSupport.getLocale("fr_FR") |
boolean | Determines if the given use is an Service Management Agent in the given project. | #if($!templateSupport.isAgent($!issue.reporter, $!issue.projectObject) ... #end |
boolean | Determines if the give comment is an Service Management Internal comment in the current issue. | #if($!templateSupport.isInternalComment($!comment)) ... #end |
TemplateIssueSearchResults | 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 |
String | Returns the Customer Visible Status name of the issue in a Service Management project. | #set($!customerVisibleStatus = $!templateSupport.getCustomerVisibleStatus($!issue) |
Issue | 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 |
String | 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 |
| Returns the time zone id set in the current user’s profile. | The issue was updated at |
| Same as above, but limits the results to the given number of issues. |
Template macros
Macro signature | Parameters | Description | Example |
#escapeHtml($value) |
| Escapes the HTML in a given value, therefore it will be displayed as text. | #escapeHtml("<p>Sample html</p>") |
#renderVersions($versions) |
| Renders the versions. | #renderVersions($!issue.fixVersions) |
#renderComments($issue) |
| Renders the public comments of the issue. | #renderComments($!issue) |
#renderCommentsInReverseOrder($issue) |
| Renders the public comments os the issue in reverse order. | #renderCommentsInReverseOrder($!issue) |
#renderCurrentCommentIfPublic() |
| Renders the current comment if it is public. | #renderCurrentCommentIfPublic() |
#renderServiceDeskPublicComments($issue) |
| Renders the public comments of the issue. | #renderServiceDeskPublicComments($!issue) |
#renderServiceDeskInternalComments($issue) |
| Renders the internal comments of the issue. | #renderServiceDeskInternalComments($!issue) |
#renderAllComments($issue) |
| Renders both public and internal comments of the issue. | #renderAllComments($!issue) |
#renderLastComment($issue) |
| Renders the last comment of the issue. | #renderLastComment($!issue) |
#renderCurrentComment() |
| Renders the current comment. | #renderCurrentComment() |
#renderComment() |
| Renders the current comment. | #renderComment() |
#renderComponents($issue) |
| Renders the components of the issue. | #renderComponents($!issue) |
#renderDateTime($dateTimeValue $pattern $timezoneId) |
| 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) |
| Formats a date field based on the pattern and the timezone. | #renderDate($!issue.created "dd MMM yyyy" "Australia/West") |
#renderLabels($issue) |
| Renders the labels of the issue. | #renderLabels($!issue) |
#renderList($listitems) |
| Renders the items into a bullet list. | #renderList($!issue.affectedVersions) |
#renderFlatList($listitems) |
| Renders the items into a comma-separated list. | #renderFlatList($!issue.affectedVersions) |
#renderProject($issue) |
| Renders the project name of the issue. | #renderProject($!issue) |
#renderDescription($issue) |
| Renders the description of the issue. | #renderDescription($!issue) |
#renderEnvironment($issue) |
| Renders the value of the Environment field from the issue. | #renderEnvironment($!issue) |
#renderIssueType($issue) |
| Renders the type of the issue. | #renderIssueType($!issue) |
#renderCustomerVisibleStatus($issue) |
| Renders the status of the issue that is visible to the customer. | #renderCustomerVisibleStatus($!issue) |
#renderStatus($issue) |
| Renders the status of the issue. | #renderStatus($!issue) |
#renderPriority($issue) |
| Renders the priority of the issue. | #renderPriority($!issue) |
#renderResolution($issue) |
| Renders the resolution of the issue. | #renderResolution($!issue) |
#renderIssueConstant($issueConstant) |
| Renders the value of the issue system field. | #renderIssueConstant($!issue.status) |
#renderOriginalEstimate($issue) |
| Renders the original estimate of the issue. | #renderOriginalEstimate($!issue) |
#renderRemainingEstimate($issue) |
| Renders the remaining estimate of the issue. | #renderOriginalEstimate($!issue) |
#renderTimeSpent($issue) |
| Renders the time spent field value. | #renderOriginalEstimate($!issue) |
#renderSummary($issue) |
| Renders the summary of the issue. | #renderSummary($!issue) |
#renderUser($user) |
| Renders the user. | #renderUser($!issue.assignee) |
#renderCommentBody($commentObject) |
| Renders the body of a comment. | #renderCommentBody($!comment) |
#renderTextWithCommentRenderer($textToRender) |
| Renders the given text with the comment renderer. | #renderTextWithCommentRenderer($!worklog.comment) |
#renderCustomField($issue $customFieldKey) |
| Renders the value of a custom field. | #renderCustomField($!issue "customfield_10006") |
#renderAllCustomFields($issue) |
| Renders the value of all custom fields on an issue. | #renderAllCustomFields($!issue) |
#renderWorklog($worklog) |
| Renders a worklog entry. | #renderWorklog($!issue.worklogs.get(0)) |
#renderWorklogs($issue) |
| Renders all worklog entries of an issue. | #renderWorklogs($!issue) |
#renderUserProperty($user $propertyName) |
| Renders one of the user's property. | #renderUserProperty($!issue.assignee "phone") |
#footer() |
| Renders the Email This Issue footer. | #footer() |
#renderLinkToCustomerPortal($issue $linkText) |
| Renders a link to the main page of the issue's customer portal. | #renderLinkToCustomerPortal($!issue "Customer Portal") |
#renderLinkToIssueCustomerPortal($issue $linkText) |
| Renders a link that points to the issue in its customer portal. | #renderLinkToIssueCustomerPortal($!issue "Customer Portal") |
#renderTemplate($templateId) |
| Renders a template. | #renderTemplate(1) |
#renderIssueComments($order $num $restriction) |
| Renders the comments of an issue. | #renderIssueComments("desc" 10 "all") |
#renderOptOutLink($linkText) |
| Renders a link that customers can use to unsubscribe from notifications. | #renderOptOutLink("Unsubscribe") |
Last updated