Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Jira sends a JSON webhook payload to JEMHC for each issue event that occurs. JEMHC uses the event content to generate notifications.  This This guide shows how to extract custom data from an event and render it in your notification templates.

Step-by-step guide

...

Preview contexts

A Preview Context contains webhook event data for a previously processed event. This context allows previews of notification Templates at edit time for render checking. In this example, we'll add custom content for the resolution of an issue. By default there are only Created, Updated and Deleted event templates, so this will be a modification to the Updated event template.

  1. Convert a received webhooks from JEMHC > Auditing > Events, into a Preview Context that can be used with Template Sets.

  2. Create Custom Macro to provide detection logic and rendering of required content

...

Creating Preview Contexts

Go to Auditing > Events and locate an issue event that has been processed.

...

Clicking the + icon converts that data into a Preview Context:

...

...

Using Preview

...

Contexts

Simplified, the webhook structure can be seen below. Full details on the webhook data structure can be found in this Atlassian documentation.

...

Date timestamps

Code Block
#set( $createdStr = $comment.created.asText() )
#set( $timeStr = $createdStr.substring($createdStr.indexOf('T')+1) )
#set( $timeSplit = $timeStr.split(":"))
<h3>Comment created date: $createdStr.substring(0,$createdStr.indexOf('T')) at $timeSplit[0]:$timeSplit[1] </h3>

Date (translate ISO dates)

Code Block
#set ($dateObj = $dateFormatter.getDate($comment.created.asText()))
$dateFormatter.format($dateObj, "dd/MMM/yy h:mm a")

Create

...

a custom macro

The System Macros show macros defined within JEMHC and inherited by all instances:

...

Code Block
#macro ( renderIssueResolved $context)
    ISSUE WAS RESOLVED!
#end

#macro ( setWorkflowTransition $context)
    #foreach ($changeItem in $context.changelog.items)
     #set ($theField = $changeItem.field )
     #set ($theTo = $changeItem.to)
     #set ($theToString = $changeItem.toString)
     #if ($theField.asText() == "status")
        #set ($workflowTransition = $theTo.asText())
     #end
    #end
#end

Testing

Below the Edit area, the Preview Context captured earlier can be selected.  This means that data will be available via the $context Velocity reference in templates. The Scratchpad allows you to enter template content and execute it in the Preview Context defined with the edited Macro. It won’t be saved and is just for validating expressions accessing data from the preview context:

...

This means that the preview icon  will dynamically do the rendering and show the result, demonstrating (a) The changelog data contained an issue status change matching what was expected, and (b) The content was rendered via macro invocation:

...

Create and modify a

...

notification template

Create a template:

...

Then set a name, make the type Issue Updated (as issue resolutions will be 'in' the Issue Updated event), and pick a theme, e.g. Jira System):

...