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.ComponentAccessorimport com.atlassian.jira.security.roles.ProjectRoleManager// Project associated with the issuedef project = issueContext.projectObject// Current Userdef user = ComponentAccessor.jiraAuthenticationContext.loggedInUser// All the roles for this user for this projectdef userRoles = ComponentAccessor.getComponent(ProjectRoleManager).getProjectRoles(user, project)*.name// The select fielddef 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"])}
It looks like you're new here. Sign in or register to get started.