Script listener for Generic Event that fires off a "Comment" event if a comment was created


I need to have notifications that are sent on whenever a comment is made.  Unfortunately not all comments result in a "Comment" event - so when I perform a workflow transition and add in a comment at the same time, JIRA fires off a "Generic Event".  If I apply a notification on the "Generic Event", then I end up getting emails even when no comment was made.

Is there a way to create a script listener that monitors JIRA for any "Generic Events" and if there was a comment made in that event, the script then fires off a "Comment" event with the comment?



1 answer

1 accepted

Add a script listener, the one you want is called "Fire an event when a condition is true". It should be configured like this:

image2015-1-9 13:16:26.png

Make sure you only select the Generic Event to listen for or you will wind up in an infinite loop.

Something fishy seems to be going on, in that JIRA seems to be firing two events... there is a related issue which I need to look at. LMK if you have any problems.


Thanks that worked... I had expected the 2nd event to have the same "context" as the first one - I need the original comment to be associated with the 2nd event, so that my notification scheme can include it in it's mail. (Right now it fires the event but has no comment) Is that possible?

I think you want a custom listener like this: In my case I configure it by creating a custom listener, and the class is examples.answers.FireACommentOnResolve, which corresponds with the above. The second clause is just for testing, I tested it by putting it both on "resolve" and "commented", but you are using a generic event.

That's awesome - I had some hassles getting it working on our slightly older Jira installation (with rather confusing folder locations) but it works wonderfully! Thanks for the help.

oh, good... thanks for letting me know.


@Jamie Echlin [Adaptavist], you mention that something seems fishy and that JIRA seems to be firing two events. I have tried to set this up just like your answer (i.e. "Fire an event when condition is true", with the same events and code that you have) but I get a NullPointerException thrown as shown below. I know it has been a while but did you notice anything similar when setting up your example?

JIRA Software (Server) v7.1.7 and ScriptRunner 4.3.5.

ERROR kristofer 708x5328x1 da4gah, /secure/CommentAssignIssue.jspa [c.a.event.internal.AsynchronousAbleEventDispatcher] There was an exception thrown trying to dispatch event [com.atlassian.jira.event.issue.IssueEvent@586ee55[issue=ITSUP-6,comment=<null>,worklog=<null>,changelog=[GenericEntity:ChangeGroup][issue,10401][author,kristofer][created,2016-08-16 11:48:50.726][id,10963],eventTypeId=6,sendMail=true,params={FIELD_LISTENER_NOTES=Fire Issue Commented in IT Support, projects=[ITSUP], issue=ITSUP-6, params={"FIELD_LISTENER_NOTES":"Fire Issue Commented in IT Support","projects":"ITSUP","events":"13","FIELD_CONDITION":"event.getComment() != null","FIELD_EVENT_ID":"6","FIELD_FUNCTION_ID":"568b9d53dd72fe9322c856e9efd6db1d08aa5ee8","canned-script":"com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.FireEventWhen","id":"190664024"}, FIELD_EVENT_ID=6, FIELD_FUNCTION_ID=568b9d53dd72fe9322c856e9efd6db1d08aa5ee8, baseurl=https://test, canned-script=com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.FireEventWhen, FIELD_CONDITION=event.getComment() != null, id=190664024, event=com.atlassian.jira.event.issue.IssueEvent@4d45ae34[issue=ITSUP-6,comment=com.atlassian.jira.issue.comments.CommentImpl@fbd7f8ce,worklog=<null>,changelog=[GenericEntity:ChangeGroup][issue,10401][author,kristofer][created,2016-08-16 11:48:50.726][id,10963],eventTypeId=13,sendMail=true,params={eventsource=workflow, baseurl=https://test},subtasksUpdated=false], bundle=com.atlassian.jira.event.issue.DefaultIssueEventBundle@34a12e7d, events=[13]},subtasksUpdated=false]] from the invoker [SingleParameterMethodListenerInvoker{method=public void com.atlassian.mywork.providers.jira.JiraEventListener.onIssueEvent(com.atlassian.jira.event.issue.IssueEvent) throws java.lang.Exception, listener=com.atlassian.mywork.providers.jira.JiraEventListener@1bf36cdd}]
java.lang.RuntimeException: java.lang.NullPointerException
at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(
at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$1$
...long stacktrace removed....
Caused by: java.lang.NullPointerException
	at com.atlassian.mywork.providers.jira.JiraEventListener.commentedOnItem(
	at com.atlassian.mywork.providers.jira.JiraEventListener.access$200(
	at com.atlassian.mywork.providers.jira.JiraEventListener$2.handle(
	at com.atlassian.mywork.providers.jira.JiraEventListener$
	at com.atlassian.mywork.providers.jira.JiraEventListener.handleEventWithTargetServiceCheck(
	... 2 filtered
	at java.lang.reflect.Method.invoke(
	at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(
	... 306 more

the comment is not added to the new event, this is a bug that will be fixed in the next release, please watch

Watching the issue! Thanks!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,088 views 4 9
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you