How to send a mail with script listener, when customfield value has changed?

Christoph Schmitz October 8, 2019

Hello I need to send a mail, when a customfield ("Group") gets changed. I already got the following, which gets processed without any ERROR but no mail is sent. Am I missing something?

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption;

if (event.getChangeLog().getRelated('ChildChangeItem').find { it.field == ("Group") } ) {

ComponentAccessor.issueEventManager.dispatchEvent(10000L, event.issue, event.user, true)


}

 

EDIT: We also use Email This Issue and in the specific project we run this script listener, we already configured a mail template and a context / notifications with the given event (10000).

1 answer

0 votes
fjodors
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.
October 10, 2019

Hello

1) Try to enable logging for your listener and check what is worng.
Below is an example how to enable logs:


import org.apache.log4j.Category;
log.setLevel(org.apache.log4j.Level.INFO)
log.info("start logging ....");


2)Try dispatchEvent(IssueEventBundle) method
From Jira API https://docs.atlassian.com/software/jira/docs/api/8.1.0/
...
dispatchEvent(IssueEventBundle issueEventBundle)
Dispatches a bundle of issue events.
...
dispatchEvent(Long eventTypeId, Issue issue, ApplicationUser remoteUser, Comment comment, Worklog worklog, org.ofbiz.core.entity.GenericValue changelog)
Deprecated.
since v6.4.10, please use dispatchEvent(IssueEventBundle).

Christoph Schmitz October 14, 2019

Thanks for your response,

how dos this method work? I mean what should be standing inside the brackets "()" to dispatch that specific event "10000". I don't code very much, so I don't really know what parameter (IssueEventBundle issueEventBundle) is.

fjodors
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.
October 14, 2019

Hi

As you can see from description, you can get IssueEventBundle from IssueEventBundleFactory interface

Check this topic https://community.atlassian.com/t5/Jira-questions/Is-it-technically-possible-to-fire-an-event-without-updating-an/qaq-p/317043

Christoph Schmitz October 14, 2019

Ok thanks alot,

it worked somehow, and with logging, i can now se that all my code gets processed. The problem now is, there is still no email sent. Am I still missing something? I mean, event gets fired, I created a "Notification" for that event and a "Template" in Jira Email this Issue.

Suggest an answer

Log in or Sign up to answer