Prevent a transition if workflow has been in a previous status

Hi Guys,

I am hoping to take the source script from the "Previous status" function in JIRA and add it as a simple script condition to block a transition if the workflow has been in "System Testing" status before. This would be designed to block access to one workflow branch and direct the issue down another branch.
Please can someone help me with this script change for this code. Please see the attached screenshot for details.

PrevStatus.jpg

 

Thanks,

David

1 answer

1 accepted

This widget could not be displayed.
Vasiliy Zverev Community Champion Sep 04, 2016

Here a code that test if an issue has been in status:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.changehistory.ChangeHistory
import com.atlassian.jira.issue.history.ChangeItemBean

for(ChangeHistory changeHistory: ComponentAccessor.getChangeHistoryManager().getChangeHistories(issue)) {
    for(ChangeItemBean changeItemBean: changeHistory.getChangeItemBeans()) {
        if (changeItemBean.getField().equals("status")) {
            if(changeItemBean.getFromString().equals("System Testing"))
            return false
        }
    }
}

return true

Slightly Groovier version of Vasiliy's code:

import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def wasItEverInSystemTesting = changeHistoryManager.getChangeHistories(issue).any { changeHistory ->
    changeHistory.getChangeItemBeans().any { changeItemBean ->
        changeItemBean.getField() == ("status") &&
                changeItemBean.getFromString() == ("System Testing")
    }
}

return !wasItEverInSystemTesting

Thanks for your help guys, much appreciated.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

512 views 3 18
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