Fast track issue based on previous status

Mike Wells
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.
April 7, 2013

Hi,

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

Example:

  • 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.

Thanks

1 answer

1 accepted

2 votes
Answer accepted
Henning Tietgens
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.
April 7, 2013

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.

Henning

Mike Wells
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.
April 7, 2013

2013-04-08 12:57:46,253 http-bio-8080-exec-32 INFO mikewells 777x15194x1 18qi3hf 192.168.201.187 /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 192.168.201.187 /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 192.168.201.187 /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 192.168.201.187 /secure/CommentAssignIssue.jspa [groovy.canned.utils.WorkflowUtils] Not attmpting transition

Any ideas why this could be happening?

Mike Wells
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.
April 7, 2013

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)
log.info("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...

Mike Wells
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.
April 7, 2013

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.

Kyle Moseley _blueridge_cx_ October 1, 2014

Very cool script.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events