Versions Compared

Key

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

...

A Preview Context contains webhook event data for a previously processed event. This context allows previews of notification Templates at edit time. 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

...

An event entry will look something like this:

...

Press (…) > View Event Data to show the webhook Webhook data:

...

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

...

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

Code Block
 {
    "timestamp",
    "webhookEvent",
    "issue_event_type_name",
    "user": {
      //  --> See User shape in thelinked linkeddocumentation
document    },
    "issue": {
        //--> See Issue shape in thelinked linkeddocumentation
document    },
    "changelog" : {
     // See Changelog shape in the linked document
   },
   "comment" : {
     // See Comment --> See Changelog shape in inlinked the linkeddocumentation
document    }

}

The $context reference used in all templates represents this webhook data structure. It important to know that it is a reference to an object of type ObjectNode.

...

The values in all nodes like $context.issue.id result in the value shown in the webhook data. For example "40301".  The quotes normally need removing, and this can be done with $context.issue.id.asText().

All ‘asText()’ values are effectively a java String object, so all related methods can then be used, eg .toLowerCase()

Most properties lie under the $context.issue.fields prefix, as shown:

...

Code Block
languagejs
#macro ( helloworld $param1 $param2)
<B>Hello $param1 -- $param2 </B>
#end

The Custom Macros are   are user editable, the following text contains the render method that will be called from our template, as well as the workflow transition detector 'helper' method.

...

This means that the preview icon Image Removedicon (Eye 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:

...

Filter by label (Content by label)
showLabelsfalse
max5
spacesJEMHC
showSpacefalse
sortmodified
showSpacetypefalsepage
reversetrue
typelabelspagetemplate webhook velocity
cqllabel in ( "velocity" , "template" , "webhook" ) and type = "page" and space = "JEMHC"labelstemplate webhook velocity
Page Properties
hiddentrue


Related issues

 


...