Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the username of a user from a string that is the full name of user

SWAPNIL SRIVASTAV
Contributor
June 1, 2020

How to get the username of a user from a string that is the full name/display name  of user in groovy script 

1 answer

1 accepted

3 votes
Answer accepted
PD Sheehan
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 1, 2020

You can try the UserSearchService

import com.atlassian.jira.component.ComponentAccessor

def users = ComponentAccessor.userSearchService.findUsersByFullName('Peter-Dave Sheehan')
if(users.size()>0){
return users.first()
}
SWAPNIL SRIVASTAV
Contributor
June 1, 2020

Hello @PD Sheehan ,

Thanks, it worked.

I found the complete script: 

import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.component.ComponentAccessor

def userSearchService = ComponentAccessor.getComponent(UserSearchService)
def users = userSearchService.findUsersByFullName("Mr Admin")

if (users) {
    users.first() // an ApplicationUser (in jira 7)
}
else {
    // no users found with that display name
}
Like Roger Hughes likes this

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events