Extract last modified by using Groovy Script?

Shreya Rawal May 15, 2015

Hi All,

I am using the following Groovy script to extract last modified by username. However when I select Text field as the Template I get the username but when I select User Picker Template I get Anonymous. I need the full name to displayed and not just the username. 

 

changeItems = componentManager.changeHistoryManager.getAllChangeItems(issue)
if (changeItems?.size()>0) {
    componentManager.userUtil.getUserObject(changeItems.sort(false).last().user)
else {
    null
}

 

Text Field returns: username:12345
User Picker returns: Anonymous
Any suggestion? 
Thanks!! smile 

2 answers

1 accepted

3 votes
Answer accepted
Alejo Villarrubia [Adaptavist]
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.
May 19, 2015

Hi,

Can you try the following code?

import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changeItems = changeHistoryManager.getAllChangeItems(issue)

if (changeItems?.size() > 0) {
    def userUtil = ComponentAccessor.getUserUtil()
    def userkey = changeItems.sort(false).last().getUserKey()
    userUtil.getUserByKey(userkey)
} else {
    null
}

The User Picker template expects com.atlassian.jira.user.ApplicationUser instead of a com.atlassian.crowd.embedded.api.User.

Ash Ray May 31, 2018

@Alejo VillarrubThanks for the get code.

How do we get Display name instead of username?

0 votes
Shreya Rawal May 19, 2015

Hi Alejo,

I am still getting the same output with the new script. Anonymous for User Picker Template and username for Text Field Template.

 

User Picker Template.png

Text Field Template.png

Alejo Villarrubia [Adaptavist]
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.
May 19, 2015

I just edited my answer. The code was returning the user name while it should have returned the ApplicationUser instead.

Alejo Villarrubia [Adaptavist]
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.
May 19, 2015

Bear also in mind that if the field uses the User Picker template, it will appear on the right hand side of the issue screen, under the People section.

Shreya Rawal May 20, 2015

That's awesome!! This works :D Thanks Alejo.

Suggest an answer

Log in or Sign up to answer