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.
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"])
}
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.