The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to restrict workflow condition

Omprakash Thamsetty
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 Champions.
June 21, 2019

Hi,

I have "Reopen" transition from HOLD and Canceled. I would like to do workflow condition as below.

 

1. When Status is HOLD and doing the transition REOPEN then PM and Admin role can perform.

2. If the status is Canceled and doing the transition REOPEN then Admin role can perform.

Can anyone tell me how to write condition script to accomplish.

 

Here I tried but now working.

import com.atlassian.jira.issue.security.IssueSecurityLevelManager
import com.atlassian.jira.issue.security.IssueSecuritySchemeManager
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)

Issue issue = issue

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

def actionId = transientVars["actionId"]
def PrevStat = changeHistoryManager.getChangeItemsForField(issue, "status").getAt(changeHistoryManager.getChangeItemsForField(issue, "status").size() -
1).getFromString()

def currentUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def projectManager = ComponentAccessor.getProjectManager()

def projectId = issue.getProjectId()
def project = projectManager.getProjectObj(projectId)
ProjectRoleManager projectRoleManager = (ProjectRoleManager) ComponentAccessor.getComponentOfType(ProjectRoleManager.class)
ProjectRole PrjMgr = projectRoleManager.getProjectRole("Project Manager")
ProjectRole admin = projectRoleManager.getProjectRole("Administrators")

def stat=issue.getStatus().getName()
log.debug " Previous Stat $stat and actionID $actionId"
def holdstatusID="11803"
def canceledID="10202"
if(issue.getStatus().getName() == 'Hold'){
if (projectRoleManager.isUserInProjectRole(currentUser,PrjMgr,project)||projectRoleManager.isUserInProjectRole(currentUser,admin,project)) {

return true;
}
}else if(issue.getStatus().getName()== 'Cancelled'){
if (projectRoleManager.isUserInProjectRole(currentUser,admin,project)) {
log.debug "current user $currentUser"
return true
}
}

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
PD Sheehan
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 Champions.
June 21, 2019

This can be done using a very simple script using the Simple scripted condition.

currentUser and isUserMemeberOfRole are already available within the binding.

if( issue.status.name.toLowerCase() == 'hold'){
isUserMemberOfRole('Project Manager') || isUserMemberOfRole('Administrators')
} else if( issue.status.name.toLowerCase() == 'canceled'){
isUserMemberOfRole('Administrators')
} else {
false
}

 

In fact, you could have the Administrators part of it as a regular non-scripted condition.

Then use the "any of the following condition" with a  single line condition

issue.status.name.toLowerCase() == 'hold' && isUserMemberOfRole('Project Manager')

simpleScriptedCondition.png

This will result in administrator always seeing the transition and Project Manager only seeing it when the current state is "HOLD" 

Omprakash Thamsetty
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 Champions.
June 21, 2019

@PD Sheehan 

Its worked fine. Thanks you so much.

TAGS
AUG Leaders

Atlassian Community Events