The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 
  • Community
  • Q&A
  • Jira
  • Questions
  • Format to restrict certain values of single-select drop-down and cascading drop-down based on roles

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

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 Champions.
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"])
}
TAGS
AUG Leaders

Atlassian Community Events