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

Script runner to pull user details for last field data change? Edited

Hi All,

I have been trying to figure out how I can use Script Runner on a Jira Server 6.3 to show a calculated value which is based on a field that has been edited by a user.

Basically I have one field that a user can edit, and by all accounts, if a user edits that field, the change is record along with the details of the user who edited it (as you can see this in the history of the jira issue).

So, I want to pull that data for that last cange of that field and display the user name in a Groovy Scripted Field.

Is this even possible?  I am ssuming I would need to run some sort of Query in my script which will return a user object type, or even just some text, and then use that result to display in the custom Scripted FIeld.

2 answers

1 accepted

0 votes
Answer accepted

Hi Tristan,

You can create a Scripted Field and it's script will be 

import com.atlassian.jira.component.ComponentAccessor

def changedItem = ComponentAccessor.getChangeHistoryManager().getAllChangeItems(issue)?.last()
"Field ${changedItem?.field} updated from user ${changedItem?.getUserKey()}"

And then in your issue view screen will get something like 

Screen Shot 2017-05-29 at 17.32.36.pngIs this what you were looking for ?

Hi Thanos,

Almost.  That gives the last changed field and the user linked with the change.  I am looking for a specific field.

Ive looked through the API and a couple of examples, and coined something together, but I don't think its the best way to do this, nor do I think it works.  How do you go about adding logging to these scripts?

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.issue.changehistory.ChangeHistory
import com.atlassian.jira.issue.history.ChangeItemBean

ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

String fieldName = 'My Custom Field'
String lastUser = 'None'

List<ChangeHistory> changeHistory

changeHistory = changeHistoryManager.getChangeHistories(issue)

for(ChangeHistory change: changeHistory){
    for(ChangeItemBean changeItemBean: change.getChangeItemBeans()) {
        if (changeItemBean.getField().equals(fieldName)){
          lastUser = change.getAuthorDisplayName()

return lastUser


Hi Tristan,

Fair enough, then you will need 

import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.*

def changedItem = ComponentAccessor.getChangeHistoryManager().getAllChangeItems(issue)?.findAll {it.field == PRIORITY}?.last()
"Field ${changedItem?.field} updated from user ${changedItem?.getUserKey()} from ${changedItem?.from} to ${changedItem?.to}"

Regarding your question about logging, have a  look at 

Brilliant!  Thanks, that is a much simpler bit of scripting.

@Thanos Batagiannis -Adaptavist- thanks for the code 

how do we get Display name instead of username?

Please help me , how to stop logging below message to jira  LOG FILE for above script ?

Script field failed on issue: SSD-1, field: My scripted field
java.util.NoSuchElementException: Cannot access last() element from an empty List

Hey Tukaram,

Can you please make sure that you did not forget to add the safe navigation operator (?) before the last() ?

regards, Thanos

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Calling all Jira Cloud users! Give us feedback on our exploration of a new navigation.

Hi everyone! My name’s Matt and I’m a product manager at Atlassian. I work in the navigation & findability space for all our Jira Cloud products. We’ve been working on trying to improve the exp...

1,039 views 16 12
Join discussion

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