Forums

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

How to allow only reporters from project role should create only Task Issuetypes in project?

Swati_Mathapati July 3, 2023

There are 10+ Issuetypes in the project ,how to allow only reporters from project role should create only Task Issuetypes in project and all others in the project role should create all other Issuetypes

4 answers

1 accepted

1 vote
Answer accepted
Evgenii
Community Champion
July 3, 2023

Hi, @Swati_Mathapati 

You can make it with ScriptRunner. If you have it, you can create behavior, and add there following script:

/*
* Created 2023.
* @author Evgeniy Isaenkov
* @github https://github.com/Udjin79/SRUtils
*/

package Examples.Behaviours

// Limit issue types, depending from user Role in project
import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
import com.atlassian.jira.issue.issuetype.IssueType
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours
ProjectRoleManager projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
Collection<IssueType> allIssueTypes = ComponentAccessor.constantsManager.allIssueTypeObjects

ApplicationUser user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
FormField issueTypeField = getFieldById(ISSUE_TYPE)
ArrayList availableIssueTypes = []

//Check Role
ArrayList<String> remoteUsersRoles = projectRoleManager.getProjectRoles(user, issueContext.projectObject)*.name

if ('Reporters' in remoteUsersRoles) {
availableIssueTypes.addAll(allIssueTypes.findAll { it.name in ['Task', 'Experiment', 'Classified Tasks'] })
} else {
availableIssueTypes.addAll(allIssueTypes.findAll { it.name in ['Task'] })
}

issueTypeField.setFieldOptions(availableIssueTypes)
0 votes
Swati_Mathapati July 5, 2023

Thank you all for your responses

0 votes
Nic Brough -Adaptavist-
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 Leaders.
July 3, 2023

There's a neat and simple script in the library for this - see https://library.adaptavist.com/entity/restrict-issue-types?tab=dataCenter

It's always worth checking the library before asking for help with a script - the library scripts are all tested (and updated when needed) by the Scriptrunner team 

0 votes
Joe Pitt
Community Champion
July 3, 2023

Jira doesn't allow you to restrict creating out of the box. There are some workarounds, but they act after someone tries to create. I suggest searching for 'stopping users from creating issues' as a start. They involve putting validators on the create step in the workflow or using scriptrunner. 

Suggest an answer

Log in or Sign up to answer