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

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 Community Champion Oct 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. 

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,899 views 12 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot