Use Static Resources
Summary
Since JEMH 2.1.15
Static Resources are files which can be uploaded to JEMH to be attached to outbound email notifications. Static resources support being attached directly to an outbound email as an attachment, or as an inlined image in the email HTML body when the resource is an image file. Static Resources can be used when a specific file is required to be attached to outbound notifications.
Management of resources
Static Resources can be created for global use, or scoped to a particular project. Static Resources can be configured from the Static Resources tab within the JEMH configuration area, or within project settings when a user has project administration permission.
JEMH Configuration | Project Settings |
|---|---|
|
|
Creation
Within the Static Resources tab click New Static Resource:
A form will appear below after pressing New Static Resource:
After you have entered the desired settings and selected a file to be used as a Static Resource, press the Submit button. A new Static Resource will be created with the associated settings and displayed in the list of resources.
Images are not dynamically rendered for page load performance, to see a preview of an image click on "click to preview", the image will be downloaded and dynamically injected into the page.
Configuration options
Project
The Project that the Static Resource will be scoped to
IMG Width
Sets the width that will be used to render the image at runtime (pixels)
IMG Height
Sets the height that will be used to render the image at runtime (pixels)
Pick a file
File picker dialogue to select the file to be uploaded as a Static Resource
Description
A description of the Static Resource
Editing
The Static Resources tab within JEMH allows existing Static Resources to be edited.
Static resources can be filtered in several ways to scope the listed resources.
A list of Static Resources is shown:
Editing an existing Static Resource by clicking the pencil icon within the actions menu on the right side of a resource:
| The Edit Static Resource form allows you to modify the current configuration of a Static Resource. You can re-scope a resource project by modifying the Project field. Image width and height can be modified via the IMG Width and IMG Height fields. Resource description can be modified via the Description field. You can also upload a new file which will overwrite the existing file mapped to the resource, choosing a new file via the Pick a file field and then pressing Submit. The new file will replace the existing file mapped to the resource whilst retaining the configuration options defined for the original file. |
Adding Static Resources to notifications
By Workflow Configuration
From v2.7.12 and v3.0.0 we also add a Static Resource picker so that specific attachments can be picked for specific transitions. Given workflow is cross project, all StaticResources are pickable.
By Script
Static Resources can be added to notifications by using JEMH's Template Sets system. Velocity script is added to a custom template, defining which resources are to be attached to outbound notifications using that Template Set.
In this example we are creating a Template Set for the Issue Created event. We will be attaching a PDF document, along with an image of a goldfish that will be embedded in the HTML body. The outcome of this example will be that a user receives an email when the Issue Created event is fired, the email will contain some text and the goldfish image within the body and the email will also have a PDF file containing terms of service attached as an email attachment.
First create an Issue Created template, for more in-depth information on the configuration of Template Sets see: Use Template Sets (Custom Templates):
Edit the newly created template by selecting the Edit action next to the item. You will now be shown the template edit screen. Enter a preview context issue key which will be used to generate template previews for use whilst designing Template Sets:
To access a Static Resource you will need to know it's unique ID, this can be found on the left hand side of the Static Resource when it is listed within the Static Resources tab.
The unique ID for our PDF document's Static Resource is 4, the unique ID for our goldfish image's Static Resource is 3.
Velocity methods
Method signature | Usage example | Description |
|---|---|---|
renderStaticResourceImage(Project project, Integer resourceId) | $jemhUtils.renderStaticResourceImage($issue.getProjectObject(), 123) | Embeds static resource images as in-line HTML images. |
renderStaticResourceImage(Integer resourceId) | $jemhUtils.renderStaticResourceImage(123) | since 2.4.1 Same as above, however can only be used for adding resources with a global scope. |
addStaticResourceAttachment(Project project, Integer resourceId) | $jemhUtils.addStaticResourceAttachment($issue.getProjectObject(), 123) | Attaches the defined Static Resource ID to the outbound notification as an email attachment. |
addStaticResourceAttachment(Integer resourceId) | $jemhUtils.addStaticResourceAttachment(123) | since 2.4.1 Same as above, however can only be used for adding resources with a global scope. |
If the notification event has a related issue, the current project object for an issue can be accessed via velocity using:
$issue.getProjectObject()Combining this all, the final velocity code to inline our goldfish image within the email whilst attaching our PDF document to the email will be:
$jemhUtils.addStaticResourceAttachment($issue.getProjectObject(), 4)
$jemhUtils.renderStaticResourceImage($issue.getProjectObject(), 3)Append the above velocity code to the Template Set HTML section, the rendered template can be previewed using the button below the text field, when a preview context issue key has been supplied in the preview section:
The image of the goldfish is embedded as part of the HTML template, the attached PDF document can not be previewed at this time but can be tested by sending an email using this template set. Press submit to save the changes to the Template Set.
Now that the Template Set has been configured it needs to be mapped to the JEMH Event Listener mapping for a project: