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

How to throw a custom issue event from a post function script (Jira 7) ?

Hello,

 

I want to throw a custom event from a post function with a groovy / script runner script in a JIRA 7 platform.

For example :

If customfield xxx has value A -> throw custom event A (to notify group A)

if customfield xxx has value B -> throw custom event B (to notify group B)

...

 

I want to use the IssueEventManager :

https://docs.atlassian.com/jira/latest/com/atlassian/jira/event/issue/IssueEventManager.html

 

The old method was simple but is deprecated since 6.4.10 :

dispatchEvent(Long eventTypeId, Issue issue, ApplicationUser remoteUser, boolean sendMail)

 

Now the only way is to use :

dispatchEvent(IssueEventBundle issueEventBundle)

 

How can i create a IssueEventBundle object ?

Maybe someone has an example with this new method ?

 

Thanks

2 answers

1 accepted

1 vote
Answer accepted

I tried :

  • Create custom events (create issue template)
  • Add them to the notification scheme
  • Use this script (post function create transition in my case) :

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

Long EVENT_ID = new Long("10000")
ApplicationUser currentUser
IssueEventBundle eventBundle

JiraAuthenticationContext jiraAuthContext = ComponentAccessor.getJiraAuthenticationContext()
IssueEventManager issueEventM = ComponentAccessor.getIssueEventManager()
IssueEventBundleFactory issueEventFactory = (IssueEventBundleFactory) ComponentAccessor.getComponent(IssueEventBundleFactory.class)

currentUser = jiraAuthContext.getUser()
eventBundle = issueEventFactory.wrapInBundle(new IssueEvent (issue, null, currentUser, EVENT_ID, true))
issueEventM.dispatchEvent(eventBundle)

It seems ok (for the part "throw custom event").

Hi Dupont,

Maybe this older AA may give you a hint How to Throw a Custom Issue Event from a Custom Listener (it makes use of the issueEventBundle)

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Off-topic

Friday Fun: Virtual dance party!

Do dance parties help you relieve stress? How about *virtual dance parties*? My team holds virtual dance parties to brighten the mood of a tough day or celebrate an upcoming weekend.  Want t...

147 views 20 8
Join discussion

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