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:

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

600
Current user belongs only to Users role, therefore the only available issue types to select from are: Query and General Request
600
Current user doesn’t belong either to Users or Developers roles, therefore no issue types will be available and the field will be disabled
600
Current user belongs only to Developers role, therefore the only available issue types to select from are: Bug, Task and New Feature
600
Current user belongs to both Users and Developers roles, therefore both the above sets of issue types are available

Restricting to a Singe 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.user

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:

600
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.

For how-to questions please ask on Atlassian Answers where there is a very active community. Adaptavist staff are also likely to respond there.

Ask a question about ScriptRunner for JIRA, for for Bitbucket Server, or for Confluence.