Script Runner Condition in Workflow transitions

Venkat Krishnamoorthy January 25, 2017

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

1 vote
Vasiliy Zverev
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.
January 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
    }
}
Venkat Krishnamoorthy January 26, 2017

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
TAGS
AUG Leaders

Atlassian Community Events