Script to display user to last update issue

Found an outdated (i.e. doesn’t work) script that returns the last user to update an issue:

I’ve updated it to make it work again. You MUST have the Search Template AND Script Runner template set to User Picker, otherwise results will return “Anonymous” user.

import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.changeHistoryManager

def changeItems = changeHistoryManager.getAllChangeItems(issue)
if (changeItems?.size() > 0) {
    ComponentAccessor.userManager.getUserByKey(changeItems.sort(false).last().userKey)
} else {
    null
}

I’d add some check that there are fewer than 1000 comments on the issue, or everything can get a bit sluggish. From experience

Matt makes an excellent point!

I’d add that you’ll want to consider where and how this field will be used, as people hitting it over the API or trying to bulk-download large numbers of issues into excel could cause issues for themselves or the system as a whole.

If you expect that type of usage, then you might want to consider a listener that sets the field value rather than a “live” field which must be recalculated on every access.

The issue event will contain the user value you’re looking for, without needing to search any history :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.