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

Help with creating a ScriptRunner listener to catch field change info

gil May 17, 2017

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

Suggest an answer

Log in or Sign up to answer
3 votes
Jonny Carter
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 18, 2017

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.

gil May 18, 2017

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.

Jonny Carter
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 24, 2017

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?

Like # people like this
Jordan Hauser February 24, 2022

Not the reporter of this issue but I just wanted to say yes, this answer is perfect and helpful to others! Thanks Jonny

-Jordan

Like Jonny Carter likes this
TAGS
AUG Leaders

Atlassian Community Events