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.
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()
Thank you! Seems like, when using issue.getAssigneeUser() or issue.getReporterUser(), adding .getDisplayName() did what I needed.
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.