Restricting Available Issue Types

Micaela Pisano April 15, 2019

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
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.
April 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?

Micaela Pisano April 16, 2019

Script.png

Errore script.jpg

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

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 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

Micaela Pisano April 16, 2019

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

ERRORE SCRIPT 2.png

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 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

Micaela Pisano April 16, 2019

Ok, i'll try.

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

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 16, 2019

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

Micaela Pisano April 16, 2019

Ok,

now i have this errore:

Error script 3.png

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 16, 2019

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

image.png

Micaela Pisano April 17, 2019

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 17, 2019

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

Micaela Pisano April 17, 2019

Ok thank you

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events