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 email template is being rendered. The macro can use any data available in the template in order to inhibit a user from notification. 

...

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

    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 #macro (inhibitSendingConditions) #end 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 Jira users may receive any type of issues)

No Formatcode
#macro (inhibitSendingConditions)
 
#if ($jemhUtils.getRecipientType() == "EMAIL_CUSTOM_FIELD" && $context.issue.fields.issuetype.name.asText() != "Bug") $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
#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) $jemhUtils.setInhibitSending(true) #end
*#
#end

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

...

Restrict notifications to particular issue field changes

The following macro checks If you add the following Custom Macro to JEMHC > Notifications > Custom Macros, it will check a list of fields that are passed to it, and only allows notification if one of the listed fields was changed.  It also allows comments to be notified.  Add the below velocity macro definition to the end of the Custom Macros list found at JEMHC>Notifications>Custom Macros.:

Code Block
languagetext
#macro (sendIfFieldChangeOrComment $fieldsToCheck)
    $jemhUtils.setInhibitSending(true)
    #set ($fieldChanged = false)
    #foreach ($item in $fieldsToCheck)
        #if ($jemhUtils.isCreateOrInChangeLog($context, $item))
            #set ($fieldChanged = true)
        #end
    #end
    #if (($jemhUtils.filterRestrictedComments($context.comments).size()>0) || ($fieldChanged==true))
        $jemhUtils.setInhibitSending(false)
    #end
#end

To call the macro in your custom template, you need to add use something similar to the following example usages:

...

...

Checking 3 fields for changes: a custom field, the issues description field, and the issues status field
code
Code Block
#sendIfFieldChangeOrComment([ "Email Sender Address", "description", "status"])
title
Checking a single field for changes: the issues standard status field
Code Block
#sendIfFieldChangeOrComment(["status"])
Note

Note the lowercase name for the standard issue fields.  The field names can be determined through viewing the webhook data for a previous event.

Filter by label (Content by label)
showLabelsfalse
max5
spacesJEMHC
sortmodified
showSpacefalse

...

reversetrue
typepage
cqllabel in ( "jemhc" , "template" , "notifications" ) and type = "page" and space = "JEMHC"
labelsjemhc template