Help with creating a ScriptRunner listener to catch field change info

Hello - I need to create a ScriptRunner listener.  In there, whenever there's an update to the JIRA issue, to the FixVersion field, then I will then trigger some action.  I need a Groovy sample code to detect what was changed in this FixVersion field (i.e. old value, new value) in order to perform some action.  Thanks.

1 answer

This widget could not be displayed.

Hi, Gil!

You can get the new and old values from the list of changeItems like so:

def change = changeItems.find {
 it['field']=='fixVersions'
}
def newValue = change['newvalue']
def oldValue = change['oldvalue']

That should work in the condition on a listener (like Send Custom Email).

You can then use those values for whatever comparisons you need to do.

Thank you Jonny for the tip.  Can you please provide some more details on this?  Example, how to get the changeItems instance, how it tied to the issue object, etc.  Thanks.

No problem. So, if you're listening on an issue event, the changeItems should be injected automatically.

You can get them manually from an IssueEvent object like this:

event?.getChangeLog()?.getRelated("ChildChangeItem")

You can also get them from an issue object using the ChangeHistoryManager, as detailed in the Total TIme In Progress sample Scripted FIeld in the docs. 

import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")

Does that help?

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in Teamwork

What teamwork quotes inspire you?

Hey everyone! My name is Natalie and I'm an editor of the Atlassian Blog and I've got a question for you: What's your favorite quote about teamwork?  We've compiled a list here, along with...

139 views 16 7
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