Versions Compared

Key

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

...

Table of Contents

Summary

Jira users, JIRA groups and Email non-Jira user email addresses can be dynamically added as recipients of Issue, Ad Hoc or Post Function notifications using Velocity scripts. The main use case of for this feature is when you depend on the event's context (like the containing issue data) to conditionally add extra notification recipients. E.g.: Notify This allows you to do things such as notify managers when the issue's priority is Critical.

It's recommended to use the standard recipients configuration (notify reporter, notify watchers, etc.) when the recipients are not conditional. 

Conditional

...

recipients

...

Issue

...

event notifications

To add conditional recipients in notifications, go to Notifications -> Issue  > Email and edit your mapping by clicking in on the Cog icon.

Under the Additional Recipients header you can find the Recipients Script field.

Image Removed

...

This field takes a user-defined Velocity template. Use Ctrl+Space in the editor to view the velocity's context ($recipientUtils's methods, $context.issue, etc.).

Resolved recipients will be added as BCC in the notifications. 

Info

JEMHCloud doesn't duplicate emails. if an email has been resolved by several configurations (static or script), the recipient will receive the notification only once.

...

Ad-

...

hoc and workflow post-function notifications

Recipients scripts can be added to AdHoc Ad-hoc and Post Function Notifications as TO, CC or BCC. Each script resolves the recipients for each type. E.g.: A recipient For example, a recipient added via the CC script resolves, will receive the email as a CC recipient.

Velocity contexts and notification mechanisms are remain the same in all three features notification types (Issue, AdHoc Ad-hoc and Post Function -function notifications).

Examples

The following examples can be used in Issue, Adhoc Ad-hoc and Post Function notification-function notifications:

##If issue
Code Block
themelanguageEclipse
text
##Use values from a given select custom field
#foreach ($item in $context.issue.fields.customfield_10265)
$recipientUtils.addEmailRecipients($item.value.asText())
#end

##If the event is an issue created event, notify a non-Jira email address
#if ($context.webhookEvent.textValue() == "jira:issue_created")
    $recipientUtils.addEmailRecipients("scripted@example.com")
#end

##If issue priority is blocker and type is bug, notify JIRAJira user johnfixall
#if ($context.issue.fields.priority.name.textValue() == "Blocker" && $context.issue.fields.issuetype.name.textValue() == "Bug")
	$recipientUtils.addUserRecipients("johnfixall557058:a8d85d49-2566-47f4-9f31-861930631857")
#end

##If issue is of project SD, notify email users devLead@mycompany.com and testLeader@mycompany.com
#if ($context.issue.fields.project.key.textValue() == "SD")
	$recipientUtils.addEmailRecipients("devLeader@mycompany.com,testLeader@mycompany.com")
#end

##If issue priority is Major, notify support level 3 group
#if ($context.issue.fields.priority.name.textValue() == "Major")
	$recipientUtils.addGroupRecipients("support-level-three")
#end

##If issue priority is Minor, notify support level 1 and level 2 groups
#if ($context.issue.fields.priority.name.textValue() == "Minor")
	$recipientUtils.addGroupRecipients("support-level-one,support-level-two")
#end

##If operation was made by CEO user or issue reporter's CEO user, notify management
#if ($context.user.key.textValue() == "ceo" || $context.issue.fields.reporter.key.textValue() == "ceo" )
	$recipientUtils.addGroupRecipients("management")
#end
Note

Add Adding a group by script (addGroupRecipients method) requires workaround user to be set.

Info

In order to know the account id of a particular user, you can use the User Finder tool in JEMH Cloud > Tools > User Finder. Copy and paste the account id into the script when adding users programmatically. 

...

Testing

Issue notifications can be tested by creating or updating Issues issues through JIRA the Jira user interface. Alternatively, you can use JEMH Cloud's email processing or JEMH Cloud's test cases features.  These actions will generate issue events that JEMH Cloud listens for

You can see these events and the processing outcome by going to JEMHC configuration - > Auditing - > Events.Image Removed

...

After being processed, an event will have a report showing the recipients resolved, notifications sent and the any problems or warnings found.  Use these reports to validate the recipients the script has resolved.  The below is an example of a an Event Report taken from JEMHC>Auditing>Events JEMHC > Auditing > Events.  As you can see, one of the notification recipients has "(Script)" after their address, which signifies that this recipient was added due to the use of a velocity script.Image Removed

...

An event can be re-processed by clicking the action Run so you can tweak the script and re-run events testing the script possibilities. 

Warning

Re-running an event will resend the emails. To avoid spamming your users, use a test mail server like mailtrap or disable the mail server by going to Notifications -> Messaging → Message Outbound.

 

 

...

Related articles

Filter by label (Content by label)
showLabelsfalse
max5
showSpacefalse
cqllabel in ( "velocity" , "notification" , "notifications" , "recipient" ) and space = currentSpace ( ) and type = "page"