Restricting Issue Types
Jira issue type schemes are not very flexible, in the sense that you cannot limit the available issue types in a project. If someone has permission to create an issue in a project, they can create every issue type in the project’s issue type scheme.
This allows you to use Behaviours to restrict which issue types are available to different categories of users.
Restricting Available Issue Types
It’s a common requirement that you would like non-core members of the project to only create certain issue types, whereas the developers should be able to create Bugs, Tasks, New Features etc.
You can use setFieldOptions
on the issue type field and restrict the available issue types accordingly.
The following script demonstrates that scenario, which you should apply as an initialiser:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def allIssueTypes = ComponentAccessor.constantsManager.allIssueTypeObjects
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueTypeField = getFieldById(ISSUE_TYPE)
def remoteUsersRoles = projectRoleManager.getProjectRoles(user, issueContext.projectObject)*.name
def availableIssueTypes = []
if ("Users" in remoteUsersRoles) {
availableIssueTypes.addAll(allIssueTypes.findAll { it.name in ["Query", "General Request"] })
}
if ("Developers" in remoteUsersRoles) {
availableIssueTypes.addAll(allIssueTypes.findAll { it.name in ["Bug", "Task", "New Feature"] })
}
issueTypeField.setFieldOptions(availableIssueTypes)
The following four outcomes are possible




Restricting to a Single Issue Type
In a slightly different scenario, where there is only one issue type allowed, we can set that issue type and lock the field.
In this example we check the roles in the current project of the remote user - if they are members only of the Users
role, we set the issue type to Query and lock the field.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
// if the current user is in the Users role only, set the issue type to "Query", and lock it
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def remoteUsersRoles = projectRoleManager.getProjectRoles(user, issueContext.projectObject)*.name
if (remoteUsersRoles == ["Users"]) {
def constantsManager = ComponentAccessor.getConstantsManager()
def queryIssueType = constantsManager.getAllIssueTypeObjects().find { it.name == "Query" }
getFieldById(ISSUE_TYPE).with {
setFormValue(queryIssueType.id)
setReadOnly(true)
}
}
For people only in the Users role the Create Issue dialog will look like this:

If this is critically important that people only create the allowed issue types, you should consider backing it up with a workflow validator (perhaps a simple scripted validator) on the Create transition. Remember Behaviours are only in effect when using the browser, not when using the REST API. |
Have questions? Visit the Atlassian Community to connect, share, and learn with other Atlassian users and experts, including Adaptavist staff.
Ask a question about ScriptRunner for JIRA, Bitbucket Server, or Confluence.
Want to learn more? Check out courses on Adaptavist Learn, an online platform to onboard and train new users for Atlassian solutions.