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
}
}
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')
This will result in administrator always seeing the transition and Project Manager only seeing it when the current state is "HOLD"
Its worked fine. Thanks you so much.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.