How to add an "elseif" condition on the workflow?

Sharon Connell October 23, 2017

Epics with a value in a custom field need to be transitioned to the next status only by a specified group of users. If the field does not have a value anyone can transition to the next status.

1 answer

0 votes
Tayyab Bashir
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.
October 23, 2017

Hi, 

You'd need add some condition in your workflow on that particular transition. If you have ScriptRunner add-on on your instance then you can add a Simple Scripted Condition and add some code to it. 

Following code will restrict the transition, if the issue has the issuetype of Epic, it has that particular customfield present/filled out on that issue. So for such issues only users who are part of the "test" group will be able to make the transitions, if no such conditions exsist, then all the users would be able to transition the issue. 

import com.atlassian.jira.component.ComponentAccessor

// Get the CustomField by its id
def customField = ComponentAccessor.customFieldManager.getCustomFieldObject(10200)

def
loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// Get the group of whose user are allowed the transition
def
group = ComponentAccessor.groupManager.getGroup("test")

// Get all the groups of the logged in user
def
groupsForUser = ComponentAccessor.groupManager.getGroupsForUser(loggedInUser)


// See if the issue is of Epic type and it has that particualr custom field
// and see if the user is part of the Groups gotten above
if (issue.getIssueType()?.name == "Epic"){
if (customField.getValue(issue)){
if (groupsForUser.contains(group)){
return true
}
else return false
}
else return true
}
else return true

Replace the id of the custom field you want, and also implement it on the particular transition condition that you want. 

Sharon Connell November 1, 2017

Tayyab - My apologies for not responding sooner. We are on Jira Software cloud and I was able to sort out the logic to create what I needed in a condition.

Screen Shot 2017-11-01 at 8.46.48 AM.png

Suggest an answer

Log in or Sign up to answer