# Customizing email templates

Email templates define the content and layout of the emails that are sent using [The Email Button and the Email Screen](https://docs.meta-inf.hu/email-this-issue/outgoing-emails/manual-emails/email-this-issue-for-jira-cloud-the-email-button-and-the-email-screen), as [Email Notification Schemes](https://docs.meta-inf.hu/email-this-issue/outgoing-emails/email-this-issue-for-jira-cloud-email-notification-schemes) or as [Workflow Post Function](https://docs.meta-inf.hu/email-this-issue/outgoing-emails/email-this-issue-for-jira-cloud-workflow-post-function), all of which you can configure  with your custom templates. To manage templates, do the following:

1\. Go to **Templates** under the **EMAIL CONTENT** menu item of the **Outgoing Mails** configuration tab.

2\. Click on **Add** to create a new template or click on the three dots and choose **Edit** to modify an already existing template.

<figure><img src="https://880912854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mf8H-oTE_fhOrUtfYrN-2724419853%2Fuploads%2FhaH1eRLGBXRWEhap48Cg%2Ftemplate_1.png?alt=media&#x26;token=b16069e8-4e8f-4720-887e-6e955bc0cd72" alt=""><figcaption><p>Templates</p></figcaption></figure>

Templates may contain static and dynamic content related to issues, projects and users, such as:

* Issue fields
* Custom fields
* Comments
* Worklog details&#x20;

It is possible to build templates from scratch, and there are predefined template themes that help to get started with custom templates.

### Themes <a href="#customizableemailtemplates-themes" id="customizableemailtemplates-themes"></a>

Themes help you to build your own templates for various goals. Click the **Add** button to add new templates from themes.

<figure><img src="https://880912854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mf8H-oTE_fhOrUtfYrN-2724419853%2Fuploads%2FjwRWMnoUy3BFVaz5UPjs%2Ftemplate_2.png?alt=media&#x26;token=10050f5f-6318-411c-80d3-9f6330c79738" alt=""><figcaption><p>Add new Template</p></figcaption></figure>

| Theme           | Description                                                                                                                           |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| All Details     | This theme is used for adding templates that render all issue fields, including custom fields.                                        |
| Issue Commented | This theme is useful for notifications on events that contain comments, e.g. when an issue is commented, or a transition is executed. |
| Issue Updated   | This theme focuses on highlighting changes made to an issue.                                                                          |
| Work Logged     | This theme gathers worklog information. It is useful for notifications on worklog-related events.                                     |
| Empty           | An empty theme for starting a template from scratch.                                                                                  |

## Building email templates <a href="#customizableemailtemplates-howanemailtemplateisbuilt" id="customizableemailtemplates-howanemailtemplateisbuilt"></a>

Email Templates may be built using using Apache Velocity Markup. Aspects to consider:

* **Basic Settings**
* **HTML Template**
* **Text Template**

### **Setting up Basic Settings**

<figure><img src="https://880912854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mf8H-oTE_fhOrUtfYrN-2724419853%2Fuploads%2FTwlsnP03B1DS9H28Fb3q%2Ftemplate_3.png?alt=media&#x26;token=40fd911b-ecab-4106-8a6f-4e385f5041e5" alt=""><figcaption><p>Basic Settings</p></figcaption></figure>

**Category:** Emails are grouped into categories. Enter any text, and a category will be automatically created if doesn't already exist. There are special categories for special uses, for instance the responses. By default, templates in this category can be selected as a canned response on the [Email Screen](https://docs.meta-inf.hu/email-this-issue/manual-emails/email-this-issue-for-jira-cloud-the-email-button-and-the-email-screen#TheEmailButtonandtheEmailScreen-EmailScreen).

### **Setting up the** Subject Template <a href="#customizableemailtemplates-subjecttemplate" id="customizableemailtemplates-subjecttemplate"></a>

Subject templates are part of an Email template. They are used for generating the final subject of the emails sent using this template. The Subject template can contain static text and dynamic content, such as issue fields and custom fields.

<figure><img src="https://880912854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mf8H-oTE_fhOrUtfYrN-2724419853%2Fuploads%2FErbivprzPocToi2Rhkzn%2Ftemplate_4.png?alt=media&#x26;token=59f21dd7-efd1-4436-9391-bd6a66fe9301" alt=""><figcaption><p>Subject Template</p></figcaption></figure>

The **$!mailSubject** variable is replaced by the subject you enter in the [Email Notification Schemes](https://docs.meta-inf.hu/email-this-issue/outgoing-emails/email-this-issue-for-jira-cloud-email-notification-schemes) or [Workflow Post Function](https://docs.meta-inf.hu/email-this-issue/outgoing-emails/email-this-issue-for-jira-cloud-workflow-post-function).

When you send a manual email, the Subject Template is used for generating the subject in the [The Email Button and the Email Screen](https://docs.meta-inf.hu/email-this-issue/outgoing-emails/manual-emails/email-this-issue-for-jira-cloud-the-email-button-and-the-email-screen). The subject you enter in the email screen is not modified further by the email templates when the email is sent.

### **Setting up the** HTML Template <a href="#customizableemailtemplates-htmlbodytemplate" id="customizableemailtemplates-htmlbodytemplate"></a>

HTML Template is used when an HTML email is sent using this email template. The HTML body may be combined with HTML and Apache Velocity Markup to give templates a customizable look and layout.

The HTML template may be developed using a WYSIWYG editor. With this editor everyone can develop templates without HTML coding experience.

<figure><img src="https://880912854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mf8H-oTE_fhOrUtfYrN-2724419853%2Fuploads%2FAxrjpuVgsFfUuNBe8yAx%2Ftemplate_5.png?alt=media&#x26;token=683af6ac-30ee-46e1-8e51-5f7fdcf6ae51" alt=""><figcaption><p>HTML Template</p></figcaption></figure>

The Rich Text editor allows users to apply formatting, add tables, images, links, preview the template and edit content in full screen.&#x20;

HTML can include issue fields and custom fields, and complex structures such as:

* Comments
* Issue link information
* Change history

To edit HTML directly, open the HTML Editor and make changes to the source code of the template.

<figure><img src="https://880912854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mf8H-oTE_fhOrUtfYrN-2724419853%2Fuploads%2Fv3ZOWZWFfTmdZCuKRNIM%2Ftemplate_6.png?alt=media&#x26;token=35cf0949-d7a6-4099-b242-ef0f27c3e865" alt=""><figcaption><p>Raw HTML Editor</p></figcaption></figure>

### Embedding images

Email This Issue can embed an image targeted by a URL on an `<img>` tag level. This way you can send out attachments of the issue, and the recipient does not need to connect and create a Jira user account to see the attachment.

To allow this feature, add the `data-embed="true"` attribute to the `<img>` element.&#x20;

Example:&#x20;

```markup
<img src="https://www.meta-inf.hu/download/attachments/35749899/icon_product_jeti.png?version=1&modificationDate=1524212907169&api=v2" data-embed="true">
```

### **Setting up the** Text Template <a href="#customizableemailtemplates-textbodytemplate" id="customizableemailtemplates-textbodytemplate"></a>

The Text Template is used for sending pure text emails with this email template.

<figure><img src="https://880912854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mf8H-oTE_fhOrUtfYrN-2724419853%2Fuploads%2FFmHn06DrMGkgh8GDjKfK%2Ftemplate_7.png?alt=media&#x26;token=d79818d0-b610-48ea-822a-03da1620386e" alt=""><figcaption><p>Text Template</p></figcaption></figure>

The Text Body part can also contain issue fields, custom fields and the same set of complex structures as the HTML Body.

### Using the Field Picker <a href="#customizableemailtemplates-fieldpicker" id="customizableemailtemplates-fieldpicker"></a>

Field Picker is a dropdown list of all issue fields and custom fields. When a field is selected, a tiny popup dialog opens with the template code fragment needed to render the value of the field in the email. Click the button in the dialog to add the code to the cursor position.

The Field Picker is available for Subject Template, HTML and Text Body templates.

<figure><img src="https://880912854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mf8H-oTE_fhOrUtfYrN-2724419853%2Fuploads%2FC418CT4w9TEycEov8WlB%2Ftemplate_8.png?alt=media&#x26;token=71bb243e-d5de-412d-ad20-2d0ab32ca3ab" alt=""><figcaption><p>Field Picker</p></figcaption></figure>

## Velocity Context for Templates <a href="#customizableemailtemplates-velocitycontextfortemplates" id="customizableemailtemplates-velocitycontextfortemplates"></a>

The following is a list of variables that are available in the email templates.

| Variable          | Definition                                                                                                                                                                                                                                                                                                                            | Example                                                                                                                                                                                                                                                                                                             | Type                                                                                                                                                         |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `currentUser`     | The current user sending the email                                                                                                                                                                                                                                                                                                    | <p><code>$!currentUser.displayName</code></p><p>Renders the full name of the current user.</p>                                                                                                                                                                                                                      | [User](https://metainf.atlassian.net/wiki/display/JETIC/API+for+Velocity+Context+Objects#APIforVelocityContextObjects-User)                                  |
| `mailSubject`     | <p>The email subject entered manually in the subject field on the manual email screen, notifications or workflow post functions.<br><br>In case of a <strong>Send auto reply</strong> action this will represent the subject of the original email.</p>                                                                               |                                                                                                                                                                                                                                                                                                                     | String                                                                                                                                                       |
| `mailBody`        | <p>The email body entered manually in the Body field in the manual email screen, notifications or workflow post functions.</p><p><br>Add this variable to all templates to render an email body entered by users.<br><br>In case of a <strong>Send auto reply</strong> action this will represent the body of the original email.</p> |                                                                                                                                                                                                                                                                                                                     | String                                                                                                                                                       |
| `issue`           | The Issue object with all available fields. The email is being sent in relation to this issue.                                                                                                                                                                                                                                        | <p><code>$!issue.summary</code></p><p>Renders the issue summary in the template.</p>                                                                                                                                                                                                                                | [Issue](https://metainf.atlassian.net/wiki/display/JETIC/API+for+Velocity+Context+Objects#APIforVelocityContextObjects-Issue)                                |
| `baseUrl`         | The base URL of the Jira Cloud site. Useful to add links to Jira screens or operations.                                                                                                                                                                                                                                               | <p>It is a simple String value you can use in building links.</p><p><img src="https://880912854-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Mf8H-oTE_fhOrUtfYrN%2F-MjTB0TRUCTl_NQSL6SD%2F-MjTKgsa15ide8isO-Px%2Fimage.png?alt=media&#x26;token=43a9c888-98d0-46a4-b650-1392b112e607" alt=""></p> | String                                                                                                                                                       |
| `issueEvent`      | The issue event if the email is being sent as an event notification.                                                                                                                                                                                                                                                                  |                                                                                                                                                                                                                                                                                                                     | [IssueEvent](https://metainf.atlassian.net/wiki/display/JETIC/API+for+Velocity+Context+Objects#APIforVelocityContextObjects-IssueEvent)                      |
| `comment`         | The comment the user enters during the operation. E.g. when editing the issue or executing a workflow transition.                                                                                                                                                                                                                     | <p><code>#renderComment()</code></p><p>Renders the comment.</p>                                                                                                                                                                                                                                                     | [Comment](https://metainf.atlassian.net/wiki/display/JETIC/API+for+Velocity+Context+Objects#APIforVelocityContextObjects-Comment)                            |
| `changeLog`       | The changelog  holding information about all fields changed during the operation. Old and new values are available.                                                                                                                                                                                                                   | <p><code>#renderChanges()</code></p><p>Renders the changelog in a readable structure.</p>                                                                                                                                                                                                                           | [Changelog](https://metainf.atlassian.net/wiki/display/JETIC/API+for+Velocity+Context+Objects#APIforVelocityContextObjects-Changelog)                        |
| `worklog`         | The worklog object holding details of the worklog entered or edited.                                                                                                                                                                                                                                                                  | <p><code>#renderWorklog()</code></p><p>Renders the worklog details.</p>                                                                                                                                                                                                                                             | [Worklog](https://metainf.atlassian.net/wiki/display/JETIC/API+for+Velocity+Context+Objects#APIforVelocityContextObjects-Worklog)                            |
| `emailCommand`    | The email definition object holding all recipients, the subject and body, the issue event and the comment details.                                                                                                                                                                                                                    | <p><code>$!emailCommand.attachment</code>s</p><p>Returns the list of attachments being added to the email.</p>                                                                                                                                                                                                      | [EmailCommand](https://metainf.atlassian.net/wiki/display/JETIC/API+for+Velocity+Context+Objects#APIforVelocityContextObjects-EmailCommand)                  |
| `sentDate`        | <p>A formatted date representing when the original email was processed by Email This Issue.</p><p>Available only in Reply/Reply all/Forward for an email.</p>                                                                                                                                                                         | <p><code>$!sentDate</code></p><p>Prints the when the email was processed by Email This Issue.</p>                                                                                                                                                                                                                   | String                                                                                                                                                       |
| `stringUtils`     | String helper methods                                                                                                                                                                                                                                                                                                                 | <p><code>$!stringUtils.isBlank($!issue.summary)</code></p><p>returns true if the issue summary is empty or null.</p><p><code>$!stringUtils.join($!issue.labels, ", ")</code></p><p>prints the labels separated by comma.</p>                                                                                        | [org.apache.commons.lang3.StringUtils](https://commons.apache.org/proper/commons-lang/javadocs/api-3.5/index.html?org/apache/commons/lang3/StringUtils.html) |
| `templateSupport` | The support object useful in templates. A constantly enhanced object, that will receive more and more methods.                                                                                                                                                                                                                        |                                                                                                                                                                                                                                                                                                                     | [TemplateSupport](https://metainf.atlassian.net/wiki/display/JETIC/API+for+Velocity+Context+Objects#APIforVelocityContextObjects-TemplateSupport)            |

## Velocity Macros <a href="#customizableemailtemplates-velocitymacros" id="customizableemailtemplates-velocitymacros"></a>

The following is the list of macros that are available in the email templates.

{% hint style="warning" %}
According to [Atlassian's announcement](https://community.developer.atlassian.com/t/deprecation-of-the-epic-link-parent-link-and-other-related-fields-in-rest-apis-and-webhooks/54048), the 'Epic Link' custom field will be deprecated as of 31th May 2022.

As a consequence, exisiting macros utilizing the 'Epic Link' value (usually in a form of `#renderCustomField($!issue 'customfield_10014'` - however, the custom field ID can vary per site) won't work after this deadline.

Please, review and consider replacing your old macros with any of our new offerings (`#renderParent` or `#renderParentEpic`).
{% endhint %}

{% hint style="info" %}
Due to some known limitations in hierarchy level retrieval for custom issue types introduced in *Advanced Roadmaps* (verified by Atlassian in [this community announcement](https://community.atlassian.com/t5/Jira-articles/Rename-epics-in-your-company-managed-projects/ba-p/1874726)), the `#renderParent` macro currently does not work as expected for higher hierarhy levels than that of Epic (1).\
E.g. `#renderParent($!issue, 2)` will not render a parent having 'Initiative' issue type (hierarchy level 2).
{% endhint %}

| Macro signature                                      | Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | Description                                                                                                                                                                                                                                                                                           | Example                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ---------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `#renderDateTime($dateTimeValue $pattern $timezone)` | <ul><li><code>$dateTimeValue:</code> the value to be formatted</li><li><code>$pattern</code>: the pattern describing the date and time format. You can find description about formatting and patterns <a href="https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html">here</a>.</li><li><code>$timezone:</code> the time zone used for formatting. You can find a list of in the <a href="../general/email-this-issue-for-jira-cloud-appendix/email-this-issue-for-jira-cloud-supported-time-zones">Supported Time Zones</a> Appendix.</li></ul>                          | Formats a `dateTime` field based on the pattern and the timezone.                                                                                                                                                                                                                                     | `#renderDateTime($!issue.created "dd MMM yyyy hh:mm a" "Australia/West")`                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `#renderIssueComments($order $num $restrictions)`    | <ul><li><code>$order</code>: "asc" or "desc"</li><li><code>$num</code>: an positive integer number or "all" to render all comments matching <code>\<restrictions></code></li><li><p><code>$restrictions:</code> comment restrictions, values are:</p><ul><li>empty: render all comments regardless of the restrictions</li><li>"none": render comments which are not limited to groups, roles or which are not internal in Service Management</li><li>"public": render Service Management public comments</li><li>"internal": render Service Management internal comments</li></ul></li></ul> | A generic, multi-purpose comment rendering macro.                                                                                                                                                                                                                                                     | <p><code>#renderIssueComments("desc" "all" "")</code> prints all comments starting with the latest one. </p><p><code>#renderIssueComments("asc" "all" "")</code>prints all comments starting with the first one. </p><p><code>#renderIssueComments("desc" "1" "")</code>  prints the latest comment.</p><p><code>#renderIssueComments("desc" "all" "none")</code> prints all comments which are not restricted. </p><p><code>#renderIssueComments("desc" "all" "public")</code> prints all public comments starting with the latest one.</p> |
| `#renderLinkToPortal($linkText)`                     | <ul><li><p><code>$linkText</code>: text to show for the link in html mails.</p><ul><li>Default value:  "View portal"</li><li>In case of a text email this parameter is ignored, and the full URL is generated.</li></ul></li></ul>                                                                                                                                                                                                                                                                                                                                                            | Renders a link to the portal with a custom text.                                                                                                                                                                                                                                                      | `#renderLinkToPortal("View Customer Portal")`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `#renderLinkToPortalRequest($linkText)`              | <ul><li><p><code>$linkText</code>: text to show for the link in html mails</p><ul><li>Default value: "View request"</li><li>In case of a text email this parameter is ignored, and the full URL is generated.</li></ul></li></ul>                                                                                                                                                                                                                                                                                                                                                             | Renders a link to the request with a custom text.                                                                                                                                                                                                                                                     | `#renderLinkToPortalRequest("Open request")`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `#renderAllComments($comments)`                      | <ul><li><code>$comments</code>: The comments to render</li></ul>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Renders all comments (both public and internal).                                                                                                                                                                                                                                                      | `#renderAllComments($!issue.comments)`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `#renderChanges()`                                   |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Renders the changelog in a readable structure.                                                                                                                                                                                                                                                        | `#renderChanges()`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `#renderComments($comments)`                         | <ul><li><code>$comments</code>: The comments to render</li></ul>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Renders the public comments.                                                                                                                                                                                                                                                                          | `#renderComments($!issue.comments)`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `#renderCommentsInReverseOrder($comments)`           | <ul><li><code>$comments</code>: The comments to render</li></ul>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Renders the public comments in reverse order.                                                                                                                                                                                                                                                         | `#renderCommentsInReverseOrder($!issue.comments)`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `#renderCustomField($issue $customFieldKey)`         | <ul><li><code>$issue</code>: the issue in the context</li><li><p><code>$customFieldKey</code></p><ul><li>key of the custom field(eg. <code>customfield\_10001</code>)</li></ul></li></ul>                                                                                                                                                                                                                                                                                                                                                                                                     | Renders the value of the custom field as displayed in Jira.                                                                                                                                                                                                                                           | `#renderCustomField($!issue, 'customfield_10603')`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `#renderLastComment($issue)`                         | <ul><li><code>$issue</code>: The issue</li></ul>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Renders the last comment of the issue.                                                                                                                                                                                                                                                                | `#renderLastComment($!issue)`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `#renderParent($issue, hierarchyLevel)`              | <ul><li><code>$issue</code>: The issue, whose parent issue shall be rendered</li><li><code>$hierarchyLevel</code>: the minimal hierarchy level of the parent issue to be rendered</li></ul>                                                                                                                                                                                                                                                                                                                                                                                                   | <p>Renders the parent issue of the issue passed as parameter, only if the hierarchy level of the parent issue is higher than or equal to the specified hierarchy level.<br></p><p>Hierarchy levels of some known issue types:</p><ul><li>sub-task: -1</li><li>task/story: 0</li><li>epic: 1</li></ul> | <ol><li><code>#renderParent($!issue, 0)</code> => renders Story/Task or higher level (e.g. Epic) parent issue</li><li><code>#renderParent($!issue, 1)</code> => renders Epic or higher level (e.g. Initiative) parent issue</li></ol>                                                                                                                                                                                                                                                                                                        |
| `#renderParentEpic($issue)`                          | `$issue`: The issue, whose parent issue shall be rendered                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | <p>Renders the parent issue of the issue passed as parameter, only if the parent issue is an Epic.</p><p>In this regard, it can be considered as a replacement for the former 'Epic Link' custom field renderer.</p>                                                                                  | `#renderParentEpic($!issue)`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |

### Assets related macros <a href="#assets_related_macros" id="assets_related_macros"></a>

{% hint style="danger" %}
Please note that the following macros display Assets Objects with **all (including hidden)** of their attributes by default. Use the $attributes parameter to customize this behavior.
{% endhint %}

| Macro signature                                                                                                                        | Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | Description                                                                                                                                                                                                                                                                                                     | Example                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| -------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>#renderAssetsCustomField($issue $customFieldKey $attributes</code></p><p><code>$runAsUserName</code></p><p><code>)</code></p> | <ul><li><code>$issue</code>: the issue in the context</li><li><p><code>$customFieldKey</code></p><ul><li>key of the custom field(eg. <code>customfield\_10001</code>)</li><li>The type of the field must be Assets Object</li></ul></li><li><code>$attributes</code> <em><mark style="color:blue;">Optional</mark></em>: the name of the attributes you want to include</li><li><code>$runAsUserName</code>: <em><mark style="color:blue;">Optional</mark></em>: a custom user name used to run AQL queries. If not provided, the query runs with the permissions of the action's initiator. Can be displayname or email address. Account id can also be specified with the following syntax: accountId:\<Jira account id></li></ul> | <p>Renders all assets objects in the field with their labels and all of their attributes or selected attributes.<br><br><mark style="color:red;"><strong>Please note that if you do not specify an attribute list all attributes (not visible, hidden, etc.) will be included in the email.</strong></mark></p> | <p>Render asset all attributes:</p><p><code>#renderAssetsCustomField($!issue, 'customfield\_10093')</code><br><br>Render asset with the created date and the status:</p><p><code>#renderAssetsCustomField($!issue, 'customfield\_10093', \['Created', 'Asset Status'])</code><br><br>With runAsUserName, without custom attributes:<br>#renderAssetsCustomField($!issue "customfield\_10006", $null, "assetsViewUser")</p>                                    |
| #renderAssetsCustomFieldAttribute($issue $customFieldKey $attributeName $runAsUserName)                                                | <ul><li><code>$issue</code>: the issue in the context</li><li><p><code>$customFieldKey</code></p><ul><li>key of the custom field(eg. <code>customfield\_10001</code>)</li><li>The type of the field must be Assets Object</li></ul></li><li><code>$attributeName</code>: the name of the attribute</li><li><code>$runAsUserName</code>: <em><mark style="color:blue;">Optional</mark></em>: a custom user name used to run AQL queries. If not provided, the query runs with the permissions of the action's initiator. Can be displayname or email address. Account id can also be specified with the following syntax: accountId:\<Jira account id></li></ul>                                                                      | Renders only the value of the attribute, which name was given                                                                                                                                                                                                                                                   | <p>Render asset attribute:<br><code>#renderAssetsCustomFieldAttribute($!issue, 'customfield\_10093', 'Name')</code><br><br>With runAsUserName:<br>#renderAssetsCustomFieldAttribute($!issue, 'customfield\_10093', 'Name', 'assetsViewUser')</p>                                                                                                                                                                                                              |
| <p></p><p><code>#renderAssets($aql $attributes $limit)</code></p>                                                                      | <ul><li><code>$aql</code>: search query in <a href="https://confluence.atlassian.com/servicemanagementserver/advanced-searching-aql-assets-query-language-1044784588.html">Assets Query Language</a></li><li><code>$attributes</code>: <br><em><mark style="color:blue;">Optional</mark></em><br>the attributes to display (used the same way as in the <code>#renderAssetsCustomField</code> macro).</li><li><code>$limit</code>:<br><em><mark style="color:blue;">Optional</mark></em><br>the maximum number of Assets Objects to display.<br>Default: 10<br>Maximum: 100</li></ul>                                                                                                                                                | <p>Renders the labels and attributes of Assets Objects returned by the given AQL query.<br><br></p>                                                                                                                                                                                                             | <p>Render assets with the default limit and all attributes:<br><code>#renderAssets('objectId IN (1, 2, 3)')</code><br><br>Render assets with custom limit and all attributes:<br><code>#renderAssets('objectId IN (1, 2, 3)', $null, 25)</code></p><p></p><p>Render assets with their Created date and Status within a custom limit of maximum 25 asset objects:<br><code>#renderAssets('objectId IN (1, 2, 3)', \['Created', 'Asset Status'], 25)</code></p> |
| `#renderAssetsLabel($aql $limit)`                                                                                                      | <ul><li><code>$aql</code>: search query in <a href="https://confluence.atlassian.com/servicemanagementserver/advanced-searching-aql-assets-query-language-1044784588.html">Assets Query Language</a></li><li><code>$limit</code>:<br><em><mark style="color:blue;">Optional</mark></em><br>the maximum number of Assets object to display.<br>Default: 10<br>Maximum: 100</li></ul>                                                                                                                                                                                                                                                                                                                                                  | Renders the labels of Assets Objects returned by the given AQL query.                                                                                                                                                                                                                                           | `#renderAssetsLabel('objectId IN (1, 2, 3)', 5)`                                                                                                                                                                                                                                                                                                                                                                                                              |

It is possible to render only the object names from an Assets field by using the `#renderCustomField($issue $customFieldKey)` macro.

## Concatenating text to URLs <a href="#customizableemailtemplates-concatenatetexttourls" id="customizableemailtemplates-concatenatetexttourls"></a>

It is possible to add certain text to a URL link in a template. Open the template in its raw HTML editor form and use the following code:

```java
#set($url = $issue.getCustomFieldValue('customfield_12345').value) <a href="$url/go" target="_blank">$url/go</a>
```

Make sure to use the correct `customfield` ID as shown in the following example:

![](https://880912854-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Mf8H-oTE_fhOrUtfYrN%2F-MjTB0TRUCTl_NQSL6SD%2F-MjTME7N-n07GdGtieW7%2Foutgoing_22.jpg?alt=media\&token=51115346-92cb-4662-b5e2-fb2f8df19b24)

## Template operations <a href="#customizableemailtemplates-templateoperations" id="customizableemailtemplates-templateoperations"></a>

Templates offer a handful of operations under the three dots.

| Template operation | Definition                                                            |
| ------------------ | --------------------------------------------------------------------- |
| Test               | Opens the Test Template dialog.                                       |
| Copy               | Opens the template editor screen with a copy of the current template. |
| Edit               | Opens the template editor.                                            |
| Delete             | Deletes the template from the system                                  |

### Testing templates <a href="#customizableemailtemplates-testtemplate" id="customizableemailtemplates-testtemplate"></a>

While developing a template it is necessary to validate the look, layout and content the template renders. For the HTML Body you can use the rich text editor's *Preview* function to check the layout and content, but the best way to validate whether a template is correct is using the *Test* operation. It allows you to enter an issue key and send yourself an HTML or Text formatted email.

<figure><img src="https://880912854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mf8H-oTE_fhOrUtfYrN-2724419853%2Fuploads%2FJFN5tNdNRAebhZd1teB3%2Ftemplate_9.png?alt=media&#x26;token=6dc0245d-ffb9-4662-a0c8-c76075624846" alt=""><figcaption><p>Test Template</p></figcaption></figure>

Once the email was sent, verify in your email app whether the content and layout was according your expectations.
