How to get the previous status of an Issue

Jackson Farnsworth
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.
September 13, 2017

I'm currently trying to use Scriptrunner Script Field to keep track of the last status of an issue in JIRA. How do I get the previous status of an issue?

1 answer

1 accepted

1 vote
Answer accepted
Daniel Yelamos [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.
September 14, 2017

Hi Jackson.

You can use te changeHistoryManager like so:

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

This will contain an arrayList of all the changes that the issue has gone through, including status changes.

My searching capabilities led me to this link, which contains an answer from another Community Champion that confirms it.

Do say if you need anymore help.

Cheers

DYelamos

Jackson Farnsworth
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.
September 14, 2017

Just curious now which item in the list returned by getAllChangeItems(issue) is the last status, and which method returns the name of the last status. The documentation on ChangeHistoryItem is less doc more just list of methods.

Daniel Yelamos [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.
September 14, 2017

Ah yes, "documentation" they call it.

As you can see in that documentation, it has a varios set of maps, one that is named FROM and another on that's named TOS. This would seem like the most logical place for the information that you are looking for.

I actually don't have a clue as to what those maps contain, but when I'm dealt bad documentation from our blue friends I usually get an instance of the object in the Script Console of SR and do something like this.

1. Get an issue with the IssueManager.

2. Get your history changes in one object, in this case, let's call it changeItems like before.

3.Then output something like this.

changeItems.getProperties().each{log.debug(it)}

 That way, you have a clear text output of what the object contains.

That should give you some more insight. If you are not self sufficient, I could find out for you if you want.

Do tell me if I can help you further.

Good luck!

DYelamos

Jackson Farnsworth
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.
September 14, 2017

For anyone's reference, getFroms() will get the state name (value) and ID (key) in some of the ChangeHistoryItems.

It's easier if you use getChangeItemsForField(Issue, Field) though and then just pull it's 'from' variable. If you're looking for something to get the last status, here it is:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager

//Gets List of all changes to 'status' and takes from last one in the list
def changeItem = ComponentAccessor.getChangeHistoryManager().getChangeItemsForField(issue, 'status')?.last()
//variable 'from' is the previous state, 'String' for String type
return changeItem?.fromString

  

Like # people like this
Daniel Yelamos [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.
September 14, 2017

Thanks for providing this information. I'm sure it will be very useful to other users.

Cheers!
DYelamos

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events