How do you access the UserEvent in a Script Listener? I'm receiving a signature error.

Patrick S
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 27, 2018

I'm trying to trigger an event when new user accounts are added, and am having trouble accessing the UserEvent in the listener.

I'm listening for "AutoUserCreatedEvent", "UserAuthenticatedEvent", "UserCreatedEvent", "UserEvent".

 

Here is a snippet of code where the error occurs.  I think the problem is that I am defining a new UserEvent, how do I access the user that is being referenced in the trigger that happened in the first place?

Code

 

import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.AbstractEvent
import com.atlassian.jira.event.user.UserEvent


def newUserEvent = UserEvent;
def appUser = newUserEvent.getUser(); // This errors (shown below)
int userEventType = newUserEvent.getEventType(); // This errors too (not shown, same idea though)

 

Error 

I think the key piece here is this "applicable for argument types: () values: []".

2018-06-27 17:08:11,907 https-jsse-nio-8443-exec-5 ERROR anonymous 1028x672557x1 - xxx.xxx.xxx.xxx /rest/api/2/search/ [c.o.scriptrunner.runner.AbstractScriptListener] Script function failed on event: com.atlassian.crowd.event.user.UserAuthenticatedEvent, file: <inline script>
groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.event.user.UserEvent.getUser() is applicable for argument types: () values: []
Possible solutions: getUser(), getTime(), getAt(java.lang.String), use([Ljava.lang.Object;), use(java.lang.Class, groovy.lang.Closure), use(java.util.List, groovy.lang.Closure)
at Script90.run(Script90.groovy:11)

 

1 answer

1 accepted

1 vote
Answer accepted
Mark Markov
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.
June 28, 2018

Hello @Patrick S

The problem here, that you dont catch event, you re just creaate User event object here.

Code must be like this

import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.AbstractEvent
import com.atlassian.jira.event.user.UserEvent


def newUserEvent = event as UserEvent;
def appUser = newUserEvent.getUser();
int userEventType = newUserEvent.getEventType();
Patrick S
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 29, 2018

@Mark Markov - Perfect, thanks!  I knew I was overlooking something fundamental.

Like Richard_J_Trawinski_Jr likes this
Mark Markov
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.
June 29, 2018

You are welcome :)

Like Richard_J_Trawinski_Jr likes this

Suggest an answer

Log in or Sign up to answer