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)
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();
@Mark Markov - Perfect, thanks! I knew I was overlooking something fundamental.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are welcome :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.