Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to find the status before the PostFunction executes

zfinannee June 14, 2017

I just spent about an hour crafting a detailed message about what I need to do, but when I submitted it, I got an error and my message was wiped out.   So I'm just going to give the bare essentials here and hopefully someone can help.

I need to know what the status of an issue was before the transition post functions are executed.

I need to skip a step in the workflow under certain conditions, so I'm using the "Fast Track Transition an issue" script, which  must be placed after the fire event function.

However, by that point, the issue's original status has been changed by the "linked status of the destination workflow step", and "issue.getStatus().name" returns the new status, not the original status.

Is there a function call that I can use to access the original status?

Thanks!
Anne

1 answer

0 votes
Neil Arrowsmith
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.
June 15, 2017

Can you access details of the issue prior to the change with originalIssue?(e.g. originalIssue.status?.name)

zfinannee June 15, 2017

No luck.  Admittedly I'm just trying things and don't understand the difference between using the status?.name vs getStatus().name, tho in the end all of these return the status that I'm transitioning to, not the status the issue was in before the transition was initiated:

  • originalIssue.status?.name
  • issue.status?.name
  • issue.getStatus()?.name
  • originalIssue.getStatus()?.name

The only way I've found yet to get the "previous" status is by putting a post function in as the very 1st step, before the "Set issue status to the linked status of the destination workflow step."   But the Fast-track transition specifically says to put it after the "Fire Event" function, so maybe the best I can do it so store off the original Status in Step 1, and then access it in my custom script after the Fire Event?

Neil Arrowsmith
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.
June 16, 2017

Ah yes. That rings a bell. There are other community posts that talk about using transientVards instead. Perhaps something here helps? https://jamieechlin.atlassian.net/wiki/display/GRV/Miscellaneous+Groovy+Scripts

zfinannee June 21, 2017

I tried a bunch of things keying off that article, but they all also give me back the destination workflow. 

Just for completeness, and in case anyone searching wants to see, I tried all of the following:

def myStep = transientVars["createdStep"] as Step
def myStepId = myStep.getStepId()
def prevStatus = ComponentAccessor.getConstantsManager().getStatus(myStepId as String)

log.debug "In fast track, prevStatus.name is " + prevStatus.name
log.debug "In fast track, prevStatus.id is " + prevStatus.id

int actionId = transientVars.get("actionId")
log.debug("The current transition id is: " + actionId)

import com.atlassian.jira.component.ComponentAccessor

def workflow = ComponentAccessor.getWorkflowManager().getWorkflow(issue)
def wfd = workflow.getDescriptor()
def actionName = wfd.getAction(transientVars["actionId"] as int).getName()
log.debug("Current action name: $actionName")

 

And got the following debug output, where 4 is the Step for Ready To Build and 31 is the transition for Ready to Build... ;)

 

In fast track, prevStatus.id is 4
The current transition id is: 31
Current action name: Ready to Build
In fast track, originalIssue.status?.name is Ready To Build

Maybe someday I'll figure out an elegant way to do it, but at this point I'm just going to store off the original status off in a variable at the beginning of the Post Function, and then compare it in the Fast Track Post Function.   

Thanks for your help!

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events