I'm trying to write a groovy script that will get the username of a user given the specified email. Here's what I have:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.bc.user.search.UserSearchService def userSearchService = ComponentAccessor.getComponent(UserSearchService) def user = userSearchService.findUsersByEmail("joe.user@mycompany.com")
How can I pull the the username out of the "user" object? If I do:
String user_key = user.first() log.info user_key
It'll print out in the log: "joe.user(juser)" but I gotta think there's a better way to pull that info than breaking apart that string.
Hello Chris.
As you can see here(the official atlassian documenation), the function getUsersByEmail returns an array of <ApplicationUsers>.
In the link you will find that if you have a variable ApplicationUser. You can simply call the method .getName()
Hope that you found this useful. If you need anymore help don't hessitate to ask.
Cheers
Dyelamos
Perfect! Exactly what I was looking for. Just had to add:
ApplicationUser my_user = user[0] log.info "The username is: " + my_user.getName()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Will just make a note in here, maybe even my future me will return here.
You can also use methods:
.getKey()
.getUsername()
.getDirectoryId()
.isActive()
.getEmailAddress()
.getDisplayName()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.