Get user/author who last changed Assignee field

- December 8, 2020

Hi all,

Our team utilizes Scriptrunner and JMWE plugins. I want to create a custom scripted field that stores the user/author that last changed the value of the Assignee field.

Referencing this community post from a couple years ago:https://community.atlassian.com/t5/Jira-questions/How-to-get-previous-changed-custom-field-data/qaq-p/829463

I figured this might be a step in the right direction:

import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = com.atlassian.jira.component.ComponentAccessor.getChangeHistoryManager()
def old = changeHistoryManager.getChangeItemsForField(issue, 'Assignee')
return old.fromString

However, this doesn't seem to return anything. It only returns 'Anonymous' when tested on an issue in which a user (JohnD) manually changed the value of Assignee. I want this to be able to return the user who last changed the Assignee field.

Is this possible?

 

1 answer

0 votes
Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 14, 2020

Hi @Ian Balas 

You can get a timePerfomed value.

Below is a scriptrunner library example used to build a past assignees panel

import com.atlassian.jira.avatar.AvatarService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.Issue
import groovy.xml.MarkupBuilder

import java.time.format.DateTimeFormatter
import static com.atlassian.jira.issue.IssueFieldConstants.ASSIGNEE

// the upper limited on the assignees to be displayed
final int historyDepth = 15
List<String> fields = new ArrayList<String>()
fields.add(ASSIGNEE)


def issue = context.issue as Issue
def counter = 0
List<Issue> issues = new ArrayList<Issue>()
issues.add(issue)

def baseUrl = ComponentAccessor.applicationProperties.getString(APKeys.JIRA_BASEURL)
def avatarService = ComponentAccessor.getComponent(AvatarService)
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

new MarkupBuilder(writer).table {
ComponentAccessor.changeHistoryManager.getChangeItemsWithFieldsForIssues(issues, fields).reverseEach {
def changeItems = it.changeItems

if (changeItems && !changeItems.isEmpty()) {
//if (changeItems.field.first() == ASSIGNEE && changeItems.newstring.first() && counter < historyDepth) {
def user = ComponentAccessor.userManager.getUserByName(changeItems.newvalue[0] as String)
def format = DateTimeFormatter.ofPattern("dd/MMM/yyyy")
def date = it.timePerformed.toLocalDateTime().toLocalDate()
if (user) {
tr {
td(
style: "width: 90px;", date.format(format)
)
td(
class: "jira-user-name user-hover jira-user-avatar jira-user-avatar-small",
rel : "admin", "id": "project-vignette_admin",
style: "margin: 1px 0px 1px 0px; height: 24px;",
href : "$baseUrl/secure/ViewProfile.jspa?name=$user.name"
) {
span(
class: "aui-avatar aui-avatar-small"
) {
span(
class: "aui-avatar-inner"
) {
img(
src: avatarService.getAvatarURL(loggedInUser, user),
alt: user.name
)
}
}
}
td(
user.displayName
)
}
}
}
counter++
// }
}
}

Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 14, 2020

Suggest an answer

Log in or Sign up to answer