Email notifications are not received with custom listener defined

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

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.

 

 

 

Thank you very much Mark smile 

custom email template worked perfectly.

Excellent, thanks for letting me know.

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.

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

75 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you