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?
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks like the "username" variable ended up containing the user key instead of the username, hence the null value. Nevermind!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.