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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Get user/author who last changed Assignee field

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 Dec 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++
// }
}
}

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you