In project with one workflow "ProjectX" with many issue types ("IssueType1" , "IssueType2", "IssueType3")
userA can create issues for all types. He is assigned to two roles (Role1 and Role2 and Role3)
userB can create issues for ("IssueType3") only
Need to create post function with ScriptRunner on the create transition to set the security level as follow:
If Role of user = "Role1" and issueType = 'Issue Type1"
then set the securityLevel to "Level1"
If Role of user = "Role2" and issueType = 'Issue Type2"
then set the securityLevel to "Level2"
If Role of user = "Role3" and issueType = 'Issue Type3"
then set the securityLevel to "Level3"
Thanks
Hi Mohamed,
Try the code below. Also make sure you place this post function AFTER ALL OTHER post function in your 'Create' transition.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.project.Project
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.issue.security.IssueSecurityLevelManager
import com.atlassian.jira.user.ApplicationUser
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueSecurityLevelManager issueSecMgr = ComponentAccessor.getIssueSecurityLevelManager()
ProjectRoleManager roleMgr = ComponentAccessor.getComponent(ProjectRoleManager)
List<ProjectRole> roleList = new ArrayList<ProjectRole>()
ProjectRole role1 = roleMgr.getProjectRole("Role 1 name")
ProjectRole role2 = roleMgr.getProjectRole("Role 2 name")
ProjectRole role3 = roleMgr.getProjectRole("Role 3 name")
roleList.addAll(role1, role2, role3)
Map<String, String> issueSecMap = new HashMap<String, String>()
issueSecMap.put("issue type name 1", "issue security level name 1")
issueSecMap.put("issue type name 2", "issue security level name 2")
issueSecMap.put("issue type name 3", "issue security level name 3")
Long secLvlId = issueSecMgr.getIssueSecurityLevelsByName(issueSecMap.get(issue.getIssueType().getName()))[0].getId()
for (int i; i < roleList.size(); i++){
if (roleMgr.isUserInProjectRole(currentUser, roleList[i], (Project)issue.getProjectObject())){
issue.setSecurityLevelId(secLvlId)
ComponentAccessor.getIssueManager().updateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, false)
break
}
}
Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.
Learn more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.