Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Someone knows if you can throw an event with script runner and process mails with Email this Issue

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

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

Send an Email or Publish to Confluence - What should you do with your release notes?

Background When you hear the words ‘Release notes’, almost always you think of an unsolicited email from a software vendor. But I am here to tell you that from our data, sending release notes via E...

138 views 1 2
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you