Can I get a user's full name from their username or user key?

Alexis Evans
Contributor
January 16, 2023

I am writing a Groovy script in Scriptrunner for Jira. I want to get a user's display name (full name). I have both the username and the jira user key (i.e. JIRAUSER00000). I'm finding a lot of articles for how to get the username from the full name, but I want to do the opposite because I want to display a user's name, and I think it looks nicer to display their full name rather than just their username. For some reason, I'm not finding a lot about that online. What's the easiest solution for this?

In case this information helps, I am getting the user from a multi-user picker custom field.

1 answer

1 accepted

2 votes
Answer accepted
Nic Brough -Adaptavist-
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.
January 16, 2023

Depends on what type of user object you have got, but I tend to work with "applicationUser"s.

This is because when you do stuff like 

issue.getAssigneeUser()

you get an ApplicationUser object.

If you are working with them, then it's really easy to get a name from that

issue.getAssigneeUser().getDisplayName() 

will fetch what they currently have as their name.

However, ApplicationUser is not the same as the other (several) types of user you can get.  It's usually quite easy to work out an ApplicationUser from most of the other types though.  

Mainly through "userManager" - in your case, you should be able to throw the id into userManager.getUserByKey or .getUserByName or .getUserById.  So, something like

def usersDisplayName = userManager.getUserByKey(JIRAUSER00000).getDisplayName()

Alexis Evans
Contributor
August 30, 2023

Thank you! Seems like, when using issue.getAssigneeUser() or issue.getReporterUser(), adding .getDisplayName() did what I needed.

Suggest an answer

Log in or Sign up to answer