Extract last modified by using Groovy Script?

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

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.

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

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

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.

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

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,801 views 11 18
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot