import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
@BaseScript FieldBehaviours fieldBehaviours
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def allIssueTypes = ComponentAccessor.constantsManager.allIssueTypeObjects
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueTypeField = getFieldById(ISSUE_TYPE)
def remoteUsersRoles = projectRoleManager.getProjectRoles(user, issueContext.projectObject)*.name
def availableIssueTypes = []
if ("Users" in remoteUsersRoles) {
availableIssueTypes.addAll(allIssueTypes.findAll { it.name in ["Query", "General Request"] })
}
if ("Developers" in remoteUsersRoles) {
availableIssueTypes.addAll(allIssueTypes.findAll { it.name in ["Bug", "Task", "New Feature"] })
}
issueTypeField.setFieldOptions(availableIssueTypes)
I am using the above code provided by adaptavist on https://library.adaptavist.com but getting the below error:
/rest/scriptrunner/behaviours/latest/validatorsByPid.json [c.o.j.groovy.user.FormField] Unsupported type class com.atlassian.jira.issue.issuetype.IssueTypeImpl in setFieldOptions()
What class to be used for setting the Issue type field?
Hi Sai,
Can I ask you which version of SR you use ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sai,
That feature was introduced in version 5.4.39 onwards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For me it's perfectly works but only when you try to open a new issue on a new tab (with only project and issuetype menu)
if you have all the screen with all the other field, the behaviour doesn't activate and i see all the issue type...
any clue ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def allIssueTypes = ComponentAccessor.constantsManager.allIssueTypeObjects
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueTypeField = getFieldById(ISSUE_TYPE)
def availableIssueTypes = []
def remoteUsersRoles = ComponentAccessor.getGroupManager().isUserInGroup(user, "cop-socloud")
def remoteUsersRoles2 = ComponentAccessor.getGroupManager().isUserInGroup(user, "cop-exaly")
if (remoteUsersRoles) {
availableIssueTypes.addAll(allIssueTypes.findAll { it.id in ["10210","12207","10000","10700","10800","10211","10305","10400","11100","10308","10300","10302","10304","10301"]})
}
else {
availableIssueTypes.addAll(allIssueTypes.findAll { it.id in [ "11100", "10210"] })
}
issueTypeField.setFieldOptions(availableIssueTypes)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.