Fast track issue based on previous status


I want to be able to fast track an issue to a specific transition based on the previous status of the issue.


  • The issue is in status 'In Progress'
  • PM puts issue 'On Hold' for business reasons
  • PM 'Restores' (transtion back to On Hold) the issue
  • Post Function of 'Restore' is to check what the previous status of the issue was as fast track to the transtion to get it to that status

The issue can be put 'On Hold' from multiple statuses

My current idea is to use the 'Fast-track transition an issue' built in script but I am not sure of the condition.

I think I would need to create a post function for each possibility (i.e On Hold --> In Progress, On Hold --> Scheduled etc) and check if the previous status was 'In Progress' for example.

I think I would need to somehow check the change history of the current issue, this is where I am coming unstuck!

Any help with my current approach would be much appreciated or other solutions to achieve the same goal.


1 answer

1 accepted

2 votes
Accepted answer

You can get the history items (changeItem) like this

changeItems = componentManager.changeHistoryManager.getAllChangeItems(issue)

Now you can sort this list and search for the last status change and the corresponding fromValue of the changeItem.


2013-04-08 12:57:46,253 http-bio-8080-exec-32 INFO mikewells 777x15194x1 18qi3hf /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.PostFunction] Starting establishing correct status to transition to
2013-04-08 12:57:46,255 http-bio-8080-exec-32 DEBUG mikewells 777x15194x1 18qi3hf /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.PostFunction] Previous Status is 'Open': true
2013-04-08 12:57:46,362 Thread-635 ERROR mikewells 777x15194x1 18qi3hf /secure/CommentAssignIssue.jspa [groovy.canned.utils.WorkflowUtils] Errors: {}
Error Messages: [It seems that you have tried to perform a workflow operation (Approve) that is not valid for the current state of this issue (J12345-82). The likely cause is that somebody has changed the issue recently, please look at the issue history for details.]
2013-04-08 12:57:46,362 Thread-635 ERROR mikewells 777x15194x1 18qi3hf /secure/CommentAssignIssue.jspa [groovy.canned.utils.WorkflowUtils] Not attmpting transition

Any ideas why this could be happening?

This is what I have so far...

import com.atlassian.jira.ComponentManager
import org.apache.log4j.Category

def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)"Starting establishing correct status to transition to")
def componentManager = ComponentManager.getInstance()
def changeHistoryManager = componentManager.getChangeHistoryManager()
log.debug("Previous Status is 'Open': "+changeHistoryManager.getChangeItemsForField(issue, "status").getAt(changeHistoryManager.getChangeItemsForField(issue, "status").size() - 2).getFromString().equals("Open"))
changeHistoryManager.getChangeItemsForField(issue, "status").getAt(changeHistoryManager.getChangeItemsForField(issue, "status").size() - 2).getFromString().equals("Open")

So line 11 is the condition, I get the second to last item from the change history (I am running this condition after the issue has effectivly transitioned back to 'On Hold' so I need to take that extra history in to consideration)

I then run the 'Approve' transtion, this has a pre-condition that only a user in project role "Project Manager" can execute the transition. I am in that role so the permissions should be good.

I get this in my log output...

Scratch that last question, the issue was that the transition I was calling wasn't available in the status. So I reworked the workflow a little and now it works. Thanks.

Very cool script.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,686 views 3 11
Read article

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