Hello,
I need to throw an event with script listener on an issue updated event. Then afterwards, the event should be processed by Email this Issue with a given Template. In Email this Issue I already uploaded a template, notification and a context for this event.
I tried everything to throw an event but no mail gets sent and I don't know why nor can I figure out why in logs. I tried following code already to throw an event:
First try:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption;
def aGroupChanged = event.changeLog.getRelated("ChildChangeItem").find { it.field == "aGroup" }
if (aGroupChanged) {
log.info("(" + event.issue.key + ") E-Mail gets sent")
ComponentAccessor.issueEventManager.dispatchEvent(10100L, event.issue, event.user, true)
Since this method is deprecated i tried something else, which I found in the community and modified it a bit:
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.issue.IssueEventBundle
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.event.issue.IssueEventManager
import com.atlassian.jira.event.issue.IssueEventBundleFactory
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventDispatchOption;
import org.apache.log4j.Category;
Long EVENT_ID = new Long("10100")
ApplicationUser currentUser
IssueEventBundle eventBundle
def aGroupChanged = event.changeLog.getRelated("ChildChangeItem").find { it.field == "aGroup" }
JiraAuthenticationContext jiraAuthContext = ComponentAccessor.getJiraAuthenticationContext()
IssueEventManager issueEventM = ComponentAccessor.getIssueEventManager()
IssueEventBundleFactory issueEventFactory = (IssueEventBundleFactory) ComponentAccessor.getComponent(IssueEventBundleFactory.class)
currentUser = jiraAuthContext.getLoggedInUser()
eventBundle = issueEventFactory.wrapInBundle(new IssueEvent (event.issue, null, currentUser, EVENT_ID))
if (aGroupChanged) {
issueEventM.dispatchEvent(eventBundle)
log.info("Issue: " + event.issue.key + " E-Mail sent");
} else if (!aGroupChanged) {
log.info("Issue: " + event.issue.key + " ERROR");
}
Some advices? Since I don't script or code very much I don't know what to do next, especially in the 2nd try, which is too complicated already for me. Thanks in advance