Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

This how-to will explain a way of exclude Email or JIRA users from notifications defining a macro evaluated when a Notifications can be conditionally prevented from being sent to Jira and Non-Jira user recipients. This is done by defining a Velocity macro (or “Velocimacro”) that is evaluated when an email template is being rendered.

The macro can use any data available in the template in order to inhibit a user from notification. 

Step-by-step guide

If the configuration in Notification Mappings is not enough for your notification rules, you can define more complex conditions overriding a system macro. This macro has been included in all the templates.

...

Enable Email users and JIRA users that you want to be notified in the project notification mapping: Notifications > Issue > Edit icon. Confirm the proper Target Audience has been selected.

...

key part of the macro that stops a notification being sent is the invocation of the method:

Code Block
$jemhUtils.setInhibitSending(true)

The velocity macro inhibitSendingConditions defined in JEMHC > Notification > Custom Macros is already called in all built in templates, so if you are using such a template already there is no need for additional template modification.

Info

Testing with Preview Context data

You can and should test your custom Macro to be sure it works as a syntax error in this macro will break all notifications.

In order to test the User Macro, we need a Preview Context, which represents a notification of change from Jira for the kind of issue event to be inhibited. You can create a preview context from JEMHC > Auditing > Events (via cog drop down at the end of each line. NOTE: JEMHC will not retain event data from Jira in JEMHC > Auditing > Events without a matching ‘notification project mapping’ (JEMHC > Notifications > Notification Mapping > Email).

Basic example

For demonstration, the following macro will prevent notifications when the issue type is “Support”.

Code Block
#macro (inhibitSendingConditions)
 
#if ($jemhUtils.getRecipientType() == "EMAIL_CUSTOM_FIELD" &&                                    ## macros are defined using #macro
#if ($context.issue.fields.issuetype.name.asText() !== "BugSupport")    ## condition for 
  $jemhUtils.setInhibitSending(true) #end

## 
## The following commented body can be used for reference if you have more recipient type driven conditions 
## 
#*
#if ($jemhUtils.getRecipientType()=="REPORTER" && false) $jemhUtils.setInhibitSending(true) #end
#if ($jemhUtils.getRecipientType()=="ASSIGNEE" && false) $jemhUtils.setInhibitSending(true) #end
#if ($jemhUtils.getRecipientType()=="WATCHER" && false) $jemhUtils.setInhibitSending(true) #end
#if ($jemhUtils.getRecipientType()=="CURRENT_USER" && false) $jemhUtils.setInhibitSending(true) #end
#if ($jemhUtils.getRecipientType()=="PROJECT_LEADER" && false) $jemhUtils.setInhibitSending(true) #end
#if ($jemhUtils.getRecipientType()=="COMPONENT_LEADER" && false) $jemhUtils.setInhibitSending(true) #end
#if ($jemhUtils.getRecipientType()=="USER_CUSTOM_FIELD" && false) $jemhUtils.setInhibitSending(true) #end
#if ($jemhUtils.getRecipientType()=="GROUP_CUSTOM_FIELD" && false) $jemhUtils.setInhibitSending(true) #end                                ## this inhibits the notification
  inhibit ASOFT                                                     ## debug text only seen during preview
#end                                                                ## ends the if block
#end                                                                ## ends the macro definition

...

If you use a different Preview Context, the scratchpad output will be updated, showing the different outcome.

Now we’ve shown how to inhibit ALL notifications for a given project, lets build that up, which involves you learning more about how to interact with the Preview Context, please read through:

If the configuration in Notification Mappings is not enough for your notification rules, you can define more complex conditions overriding a system macro. This macro has been included in all the templates.

  1. Enable Email users and JIRA users that you want to be notified in the project notification mapping: Notifications > Issue > Edit icon. Confirm the proper Target Audience has been selected.

  2. Add the inhibitSendingConditions custom macro in Notifications > Custom Macros > Edit. The following example uses the recipient type and the event data to only notify Bug issues to Email users (Jira users may receive any type of issues)

Code Block
#macro (inhibitSendingConditions)
#if ($jemhUtils.getRecipientType() == "EMAIL_CUSTOM_FIELD" && false) $jemhUtils.setInhibitSending(true) #end
#if ($jemhUtils.getRecipientType()=="JEMHC_ADMIN" && false) $jemhUtils.setInhibitSending(true) #end
#if ($jemhUtils.getRecipientType()=="OTHER" && false)$context.issue.fields.issuetype.name.asText() != "Bug")
  $jemhUtils.setInhibitSending(true)
#end
*#
#end

If a notification has been inhibited for sending, you should see the following line in the event's report:

...