Forums

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

Format to restrict certain values of single-select drop-down and cascading drop-down based on roles

Prayuja Patil
Contributor
April 9, 2018

If 'product' is my custom field and 'xxx','yyy','zzz' are options for it. And p1,p2,p2 are my project roles. Then, it should work like this

For p1-----> 'xxx','zzz'

For p2----->'zzz','yyy'

For p3----->'zzz'

I want groovy script for this.

1 answer

1 accepted

1 vote
Answer accepted
Roland Holban (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.
April 13, 2018

Try this. Of course you need to replace "sample select field", "p1", "xxx", etc. with the appropriate names.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager

// Project associated with the issue
def project = issueContext.projectObject
// Current User
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
// All the roles for this user for this project
def userRoles = ComponentAccessor.getComponent(ProjectRoleManager).getProjectRoles(user, project)*.name

// The select field
def field = getFieldByName("Sample Select Field")

if (userRoles.contains("p1")) {
field.setFieldOptions(["xxx", "zzz"])
} else if (userRoles.contains("p2")) {
field.setFieldOptions(["yyy", "zzz"])
} else if (userRoles.contains("p3")) {
field.setFieldOptions(["zzz"])
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events