Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Get JIRA username from email

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.

1 answer

1 accepted

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()

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()

Like stsci likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

579 views 5 20
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you