Script Runner Condition in Workflow transitions

Hello,

I am trying to set criteria on when a transition is allowed in a certain workflow. Its based on two conditions -

1) Custom Select Field value

2) user needs to be part of a certain group

 

The following is a "Custom Script Condition" I added on the transition condition.

There are no syntax errors in the following but I dont see the expected behavior -

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def DBCCTypeCf = customFieldManager.getCustomFieldObject("customfield_12323")
def DBCCType = issue.getCustomFieldValue(DBCCTypeCf)

passesCondition=false

def groupManager = ComponentAccessor.getGroupManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

if (DBCCType == "Data Update") {
if (groupManager.isUserInGroup(currentUser, "Team DBCC Approver")) {
passesCondition=true
return
}
}

 

I have a suspicion that its to do with this check -

if (DBCCType == "Data Update") {

This doesnt work for Issues where this criteria is true.

 

Thanks,

Venkat

1 answer

This widget could not be displayed.
Vasiliy Zverev Community Champion Jan 25, 2017

I assume that DBCCType is selected list type. Since here is a refactored code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option

Option DBCCType = (Option) issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12323"))
passesCondition = false

if (DBCCType.getValue() == "Data Update") {
    def currentUser = ComponentAccessor.getJiraAuthenticationContext().getUser().directoryUser
    if (ComponentAccessor.getGroupManager().isUserInGroup(currentUser, "Team DBCC Approver")) {
        passesCondition=true
        return
    }
}

Works great! I guess it was the type casting that I was missing.

I appreciate your help!

Thanks.

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

507 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