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

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

86 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