Forums

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

Is there a way to restrict Jira field "Component/s" chosen values?

Jason Liu
Contributor
January 11, 2023

We have a lot of components and they are in different forms. We have a kind of issue type for example Story, I need it can only choose some of the components, not all of them. Is that possible? For example, project components are 1,2,3,4,5 and Story can only choose 1 and 2.

1 answer

1 vote
Ashley Hudson
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.
January 11, 2023

Heya @Jason Liu

So one method that I'm aware of is utilising this script runner code here:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import static com.atlassian.jira.issue.IssueFieldConstants.COMPONENTS

def projectRoleManager = ComponentAccessor.getComponent ProjectRoleManager.class
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def targetRoleName = 'Special Users'
def project = getIssueContext().projectObject
def projectComponents = project.components
def currentUserRoleNames = projectRoleManager.getProjectRoles(currentUser, project)*.name

if (!currentUserRoleNames.contains(targetRoleName)) {
getFieldById(COMPONENTS).setFieldOptions(
projectComponents.findAll {
it.name in [
'02-HELPDESK',
'03-SECURITY'
]
}.collectEntries {
[
it.id.toString(),
it.name
]
}
)
}

If you don't have script runner let me know and I'll think of another solution for you! :)

Kind Regards,

Ashley Hudson

Bharathi Ranganathan August 9, 2023

is there any other method to do it without script runner?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.5.2
TAGS
AUG Leaders

Atlassian Community Events