Forums

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

Getting the user id from ChangeHistoryItem

Artemy Matvienko
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.
March 21, 2018

I'm trying to extract and display users from an issue's change history. The problem is that the ChangeHistoryItem lets you grab the username via the getUserKey function, however, usernames can change, therefore, this is not a reliable way to extract the users. I am seeing entries where the same user appears multiple times because of the different usernames they went by. I want the user to just be one record with the most current username, regardless of previous usernames. There doesn't seem to be a way to get the id of the user that made the change. Is there a workaround for this?

 

1 answer

1 accepted

0 votes
Answer accepted
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 22, 2018

At least within the current versions of Jira I don't think this is possible to do with just that method.  This is because by design Jira is expecting to use the user_key value in the ChangeHistoryItem.  If the username in Jira has never been renamed, then the user_key will match the username field.  However Jira allows you to rename accounts at least since version 6.0.

Because of this Jira created a new database table back in that version called app_user.  This table just has the user_key field and another field called lower_email_address.  When a user is renamed, there data is changed in other tables, but the user_key field is expected to never change within Jira.

There is an existing feature request to use the actual username as per https://jira.atlassian.com/browse/JRASERVER-61871

That said, I think you might be able to use another method, UserKeyService, in order to take the user_key value and then find the current user with that username.  The limitation here is that I don't believe Jira will be able to tell you definitively that the user that matches to that user_key now is always the same user that matched to that when this changehistoryitem event occurred, but it's a start.

Artemy Matvienko
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.
March 29, 2018

I've implemented a function that I've plugged into my code to replace the usernames with userkeys. However, the user key that is returned from the getKeyForUsername function is null for the user that had their username changed (the username is no longer "artemy"). Any idea why that may be happening? The default admin user account retrieves a user key of "admin" instead, as expected.

userkey.PNG

Artemy Matvienko
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.
March 29, 2018

Looks like the "username" variable ended up containing the user key instead of the username, hence the null value. Nevermind!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events