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

How can I programatically retrieve a username from a display name on Jira?

tommy guo
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 27, 2013

I know there exists a function in UserUtil that allows for retrieving the display name from the username I was wondering if a reverse function exists or if it would be possible to code such a function?

6 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Henning Tietgens
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 27, 2013

You can use getUsers() from UserUtil to get all user objects and grep the ones with matching display names from the list manually.

Alexej Geldt
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 11, 2015

this is not quite a good idea for large scaled applications. we have a couple of hundred thousand of users registered in the system. Consider about performance when iterating all of them.

0 votes
carle May 1, 2014

BTW... Thanks for writing "SCRIPT RUNNER" :-)

0 votes
carle May 1, 2014

Ha Ha! Too funny. Unfortunately, you're not all that right.

It was not deprecated in 5.2.4.1, which is what we use; and seeing

the "Deprecated" compiler directive is now there, meant you were wrong,

and then fixed it. But I'm glad to hear that future releases will be easier

to work with.

And I do respect your abilities, Jamie; so just so I don't sound like a snob,

I am duplicating the method, in the very same package you showed me, us,

everyone, to let you know I'm not smoking something funny. :-)

Found at line 102 of 451 in ChangeHistoryItem.java

public String getUser()

{

return user;

}

Cheers,

Carl

JamieA
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.
May 1, 2014

That's ok, it happens.

JamieA
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.
May 1, 2014

;-) no problem.

But in your case getUser returns a string, which should be the user name, not the display name. The methods haven't really changed, just the variable names and the deprecations.

0 votes
carle April 30, 2014

No Jamie. You're WRONG, I say respectfully. Something has gone wrong in your Jira design.

i.e. ChangeHistoryItem the getUser() method returns the display name instead of the userName.

Doh! Right?

Yep. Right.

JamieA
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.
April 30, 2014

No sir YOU ARE WRONG. Right? No.

com.atlassian.jira.issue.changehistory.ChangeHistoryItem#getUser

is

@Deprecated
    public String getUser()
    {
        return userKey;
    }

It returns the user key. Maybe you are thinking of another method.

ChangeHistoryItem contains a value and a string value, maybe you are picking the wrong one.

0 votes
JamieA
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 27, 2013

The fact that you're asking means something has gone wrong somewhere in your design.

Alexej Geldt
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 11, 2015

not necessarily. I have a case where i need to fetch multiple users by a part of their full name. Our users have a plugin where they reassign a collection of issues. The usernames in the system are autogenerated and therefore too cryptical. Nobody wants to type random generated strings to fetch some user. Instead they want to write full names and get suggestion options updated while they are typing. So there is a valid use case for fetching users by full name even tho they are not unique. After all, even in case where one single user is required it makes sense to fetch by full name. When multiple users exist whose full names have a match, it can be handled as error case. So Error Message could be displayed: Distinct User Required. One could also provide resolution option for this case, letting the user decide which of multiple matching users he wants to specify.

0 votes
Mizan
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 27, 2013

Display name is not unique username is unique that is the reason there is no such method available in the JIRA API .

tommy guo
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 27, 2013

Ok but would it be possible to retrieve a list of all user names corresponding to a particular display name?

Alexej Geldt
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 11, 2015

this cannot be the reason for that because there are valid use cases requiring matching multiple users by a part of their full name. In example when you are about to build suggestion options for user picker dropdowns and your users don't like to type the usernames which are often generated and dont say anything to other users.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events