Email notifications are not received with custom listener defined

RPandyaram
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 4, 2016

Hi all,

 

For one of the requirements that we have at the moment , custom listener from the script runner will be an option

The following listener that I used , is working fine .However email notifications are not sent for any updates.

 

Custom Listener on script runner.JPG

 

void issueUpdated(IssueEvent event)
{

try
{
Issue issue = event.getIssue()
if (issue.getIssueType()== "EPIC" )
{
List changeItems = event.getChangeLog().getRelated("changeItem")
if( changeItems.any {it.get('field')=='Fix Version/s'} )
{
def projectManager = issue.getProjectObject().getProjectLead().emailAddress
Email email = new Email( projectManager )
email.setSubject("Ticket ${issue.getParentObject()} Requires Review")
email.setBody("The Fix Version is updated recently for the issue $issue")
email.setMimeType("text/html")

SingleMailQueueItem item = new SingleMailQueueItem(email)
try {
ComponentAccessor.getMailQueue().addItem(item);
} catch (Exception e) {
log.warn("ERROR SENDING TICKET WATCHER EMAIL", e);
}
}
}
}

2 answers

1 accepted

1 vote
Answer accepted
Mark McCormack _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 5, 2016

Hi RP,

Assuming you are using the latest version of ScriptRunner you could configure a built-in script listener called "Send a custom email" (rather than write your own).

To configure it:

  • Give it a note like "If Epic and FixVersion changes - send an email"
  • All projects
  • "Issue Updated" event
  • Use this condition
import com.atlassian.jira.component.ComponentAccessor
issue.issueType.name == 'Epic' && changeItems.any {
	ComponentAccessor.fieldManager.getOrderableField("fixVersions")
}
  • Use this Email Template
The Issue $issue has changed it's FixVersion field 
to: ${issue.fixVersions}
  • Use this Subject Template
Ticket $issue - requires review
  • Choose html for the email format (or text)

I hope that helps.

Mark.

 

 

 

RPandyaram
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 5, 2016

Thank you very much Mark smile 

custom email template worked perfectly.

Mark McCormack _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 5, 2016

Excellent, thanks for letting me know.

WojciechW December 16, 2016

Is there a good way to actually send custom emails using custom piece of scripted code? I'd prefer to have my code versioned inside any source control system and to deploy it to production JIRA using CI environment as opposed to having simple JIRA 'send custom email' configuration. There is no way of keeping track of changes to this configuration as long as it has to be manually filled in by human on the JIRA admin pages.

In my case I also need to diversify recipient list based on the actual project. For that purpose custom script listener looks like the best and only option I have.

0 votes
RPandyaram
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 5, 2016

From the payload , the message is 

 

"event": "com.atlassian.jira.event.issue.IssueEvent@7f313b61[issue=DPDK-48,comment=<null>,worklog=<null>,changelog=[GenericEntity:ChangeGroup][issue,15510][author,jadmin][created,2016-07-31 19:33:41.958][id,19945],eventTypeId=2,sendMail=true,params={eventsource=action, baseurl=http://testtriangle-atlassiansupport.com:8081/jira},subtasksUpdated=true]",
    "clazz": "{null/empty} (java.lang.String)",
    "bundle": "com.atlassian.jira.event.issue.DefaultIssueEventBundle@5225d86e",
    "events": "[2, 10200, com.atlassian.jira.issue.fields.event.FixVersionCreatedInline] (java.util.ArrayList)"
}

Suggest an answer

Log in or Sign up to answer