It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Restricting Available Issue Types

I need to limit the creation of some issuetypes in a project and for users of a specific role.
I used this script but it still gives me an error.

 

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 ["Bug"] })
}

if ("Developers" in remoteUsersRoles) {
availableIssueTypes.addAll(allIssueTypes.findAll { it.name in ["Task"] })
}

issueTypeField.setFieldOptions(availableIssueTypes)

1 answer

0 votes
Payne Seal Community Leader Apr 15, 2019

Your script works fine for me (tweaking the user roles and issue types to match my environment). What sort of error are you receiving?

Script.png

Errore script.jpg

The errors are of this type.
what should i change?

Antoine Berry Community Leader Apr 16, 2019

Hi Micaela, 

I think Issue_TYPE should be all capitals instead : ISSUE_TYPE. Otherwise just save the script as is, ignore the warnings/errors.

Antoine

Even putting all caps on does not work.
This is the error:

ERRORE SCRIPT 2.png

Antoine Berry Community Leader Apr 16, 2019

You are not supposed to run this script in script console, but instead create a behaviour linked to the "Issue Type" field.

Then it should work fine (because issueContext will exist at execution time).

Antoine

Ok, i'll try.

What should I change to be able to run the script only for a specific project?

Antoine Berry Community Leader Apr 16, 2019

Just configure the behaviour so it applies only to the specific project (Add Mapping). :)

Ok,

now i have this errore:

Error script 3.png

Antoine Berry Community Leader Apr 16, 2019

You are missing a "," between user and issueContext. Also as I said you need to create a behaviour (GG > Behaviours)

image.png

Thanks, it works now, but this solution does not work with jira JIRA Software 7.10.0 while it works with version 7.9.0.
Can anything be done?

Antoine Berry Community Leader Apr 17, 2019

This is beyond my knowledge, you would need to contact someone from adaptavist (raise a support ticket). 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

960 views 7 0
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you