Exposing transition names based on a given issue status (using Groovy)
Many use cases from our customers involve working with issue status(es). However, there might be particular scenarios where a customer might be required to retrieve a transition name(s) (based on an issue's current/previous status).
 Instructions
Depending on the customer's use case, two possible scenarios can be considered:
Things get pretty straightforward if the customer would like to get a currently executed transition name. You can freely use the
getCurrentTransition().get().name
method + property to get the transition name.
Limitation: the getCurrentTransition()
method (hence the getCurrentTransition().get().name
property) only works when used as part of a workflow configuration. This method will not retrieve any data when used as part of an Event-based action.
Â
The customer wants to retrieve the transition names associated with the previous and current status. In this case, a Groovy script that uses some of the standard Jira classes can be used. The code snippet below that can be used for this purpose.
Limitation: as this proposed solution is based on statutes, the returned results won't be unique (meaning a single value) if multiple transitions can lead to the same status.
Additional note below from our L3/dev team:
Suppose multiple transitions lead to a specific status. In that case, there's no easy way to know which one has been executed: Jira stores that information only in the internal OS_HISTORYSTEP database table, which has no public API.
import com.opensymphony.workflow.loader.ActionDescriptor
import com.opensymphony.workflow.loader.StepDescriptor
def workflow = ComponentAccessor.getWorkflowManager().getWorkflow(issue)
def workflowStatuses = workflow.getLinkedStatusObjects()
def currentStatus
def prevStatus
prevStatus = workflowStatuses.find{item -> item.name == issue.getFieldHistory("status").fromString.last()}
currentStatus = workflowStatuses.find{item -> item.name == issue.getFieldHistory("status").toString.last()}
StepDescriptor stepDescriptor1 = workflow.getLinkedStep(prevStatus)
StepDescriptor stepDescriptor2 = workflow.getLinkedStep(currentStatus)
As an example of this second scenario, the capture below shows the output for the script when used as part of an Email Issue post-function (Email Issue) configuration (Html Body section).
 Related articles
Â