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

Paul Sainsbury January 9, 2015

Hi,

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?

 

From
  Paul

1 answer

1 accepted

4 votes
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 9, 2015

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.

 

Paul Sainsbury January 9, 2015

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?

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 13, 2015

I think you want a custom listener like this: https://gist.github.com/jechlin/2824046dd7a4ada6bc3e 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.

Paul Sainsbury January 20, 2015

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.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 21, 2015

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

Kristofer Hansson Aspman _Riada_ August 16, 2016

Hi!

@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 192.168.33.1,127.0.0.1 /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(SingleParameterMethodListenerInvoker.java:50)
at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$1$1.run(AsynchronousAbleEventDispatcher.java:48)
 
...long stacktrace removed....
 
Caused by: java.lang.NullPointerException
	at com.atlassian.mywork.providers.jira.JiraEventListener.commentedOnItem(JiraEventListener.java:394)
	at com.atlassian.mywork.providers.jira.JiraEventListener.access$200(JiraEventListener.java:46)
	at com.atlassian.mywork.providers.jira.JiraEventListener$2.handle(JiraEventListener.java:79)
	at com.atlassian.mywork.providers.jira.JiraEventListener$4.run(JiraEventListener.java:182)
	at com.atlassian.mywork.providers.jira.JiraEventListener.handleEventWithTargetServiceCheck(JiraEventListener.java:225)
	... 2 filtered
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:36)
	... 306 more
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 29, 2016

the comment is not added to the new event, this is a bug that will be fixed in the next release, please watch https://productsupport.adaptavist.com/browse/SRJIRA-2005

Kristofer Hansson Aspman _Riada_ September 5, 2016

Watching the issue! Thanks!

Suggest an answer

Log in or Sign up to answer