Fast track issue based on previous status

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
Henning Tietgens Community Champion Apr 07, 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

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?

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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published yesterday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

71 views 0 5
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