Send issue creation notification for particular nominated recipients


In this scenario, we will send an issue creation notification for a Sender (who can be either a Jira or a non-Jira user), the first 5 recipients from the To email header and the first 5 recipients from the Cc header. Also, the users can be either Jira or non-Jira users. To achieve this functionality, we will need to create 2 custom fields (one for storing non-Jira sender/reporter and the second one for storing all nominated recipients (5 of the To and 5 of the Cc recipients)), 2 custom issue creation notification templates (where needs to be applied velocity scripts) and 2 notification mappings (one for Jira and second for non-Jira users).

Step by step guide

1. Creation and configuration of custom fields

  • Under _Jira > Issues > Fields > Custom fields_ create 2 custom fields. In this example, we will create Nominated Recipients and Sender Email Address.

  • Once created, we need to configure the Nominated Recipients and Sender Email Address custom fields.
    Nominated Recipients
    Configure as a Custom field defaults under JEMH > Profiles > Project Mappings > edit corresponding project mapping > Custom Field Defaults. During the creation of a custom field default, apply the following:
    Field Value Type - Velocity Scripted Value
    Value -

    #set ($counter = 0) #foreach ($address in $toAddresses) #if($counter < 5) #if($address != $jemhUtils.getCatchEmailAddress()) $address, #end #set ($counter = $counter+1) #else #set ($counter = 0) #break #end #end #foreach ($address in $ccAddresses) #if($counter < 5) #if($address != $jemhUtils.getCatchEmailAddress()) $address, #end #set ($counter = $counter+1) #else #set ($counter = 0) #break #end #end

Apply Rule - Create only

Sender Email Address
Configure it under JEMH > Profiles > Email > Sender Processing > Non-Jira user sender address to Text custom field

2. Creation of issue creation custom templates

Under JEMH > Template Sets > Templates create 2 issue creation event type custom templates, one for Jira users and the second one for non-Jira users. The purpose of having a custom velocity login inside the non-Jira custom template is to prevent notification duplication for Jira users who exist in both places such as the custom field (nominated recipients) and the Jira field (Request Participants).

Jira users template

Apply the following velocity script

## To inhibit initially all notifications $jemhUtils.setInhibitSending(true) ## Nominated Recipients - this is a created custom field which contains all nominated reciepients (first 5 of To and first 5 of Cc) #set ($allNominatedRecipients = $customFieldManager.getCustomFieldObjectByName("Nominated Recipients")) ## if the recipient email address matches the address from the custom field send a notification #if($allNominatedRecipients.getValue($issue).contains($recipientEmail)) $jemhUtils.setInhibitSending(false) #end ## send notification for the reporter if the reporter is a Jira user. customfield_10200 - this is a custom field for Sender Email Address #if(!$issue.getCustomFieldValue("customfield_10200")) #if($recipientEmail.equals($issue.reporter.getEmailAddress())) $jemhUtils.setInhibitSending(false) #end #end

Non-Jira users template

Apply the following velocity script

## The purpose of this script is to avoid duplicate notifications for Jira users who exist in both field Nominated Recipients and Request Participants #set ($allNominatedRecipients = $customFieldManager.getCustomFieldObjectByName("Nominated Recipients")) #if($allNominatedRecipients.getValue($issue).contains($recipientEmail)) #if($jemhUtils.getUserByEmail($recipientEmail)) $jemhUtils.setInhibitSending(true) #end #end

3. Creation and configuration notification project mappings

Create notification mapping for Jira users and non-Jira users under JEMH > Notifications

Configure all required settings for notification mappings as per documentation . Then for Jira notification mapping select your created custom template for an issue creation event.

For non-Jira notification mapping, select 2 created custom fields in the CSV email Custom Fields and select your created custom template for issue created event


Test case

Contains non-Jira sender, 8 To recipients and 7 Cc recipients

Issue created

Only added to the Nominated Recipients field first 5 of the To recipients and first 5 of the Cc recipients

Notification History

This shows that notifications have been sent for the reporter and 10 recipients in total