Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

How can I use Scriptrunner Jobs to trigger Custom Event picked up by a Listener?

Hello,

I'd like to set up a Scriptrunner Custom Scheduled Job to send a Custom Event once per day. This custom event would then be picked up by a Listener (for issue events) and fire off a custom email rounding up some key information.

I realize that I can also generate emails directly from a Custom Job, but the Listener interface is much easier for generating a complex HTML template with in-line database queries.

I have the following code, which seems to fire the event off just fine:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEventManager
import com.atlassian.jira.event.issue.IssueEventBundleFactory
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.issue.IssueEventBundle
import com.atlassian.jira.issue.Issue


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

def userManager = ComponentAccessor.getUserManager();
def automationUser = userManager.getUserByName("user_name");
Issue issue

int EVENT_ID = 10100

IssueEventBundle eventBundle = issueEventFactory.wrapInBundle(new IssueEvent (issue, null, automationUser, (Long)EVENT_ID, true))
issueEventM.dispatchEvent(eventBundle)

However the Listener errors out and I am not sure why. Possibly the dummy issue and dummy user used to dispatch the event? The listener currently has no code in it, just an HTML template that triggers on Event 10100.

Here is part of the Listener log:

at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
	at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:70)
	at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:53)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.eclipse.gemini.blueprint.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:57)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
	at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
	at com.sun.proxy.$Proxy7043.execute(Unknown Source)

 

1 answer

For what it's worth, in my Jira 9.5.1 DC instance, this code worked just fine.

My listener is quite involved.
It works with a 'stock' 'Generic Event' (13l for me) as well as a custom event (10202l).

I'm not using a dedicated user, but just the 'loggedInUser'.
So your suspicion towards the 'dummy-user' might just be well deserved ...

Suggest an answer

Log in or Sign up to answer