Hi Team,
We have a requirement to remove three specific issue types—"Epic," "Enabler," and "Feature"—from hundreds of Jira projects. However, we want to keep the existing tickets under these issue types for all projects. Since these 100+ Jira projects have various other issue types, I cannot simply include them all in the user roles. Therefore, I want to exclude these three issue types. I tried using the following ScriptRunner behavior, but it still shows all the issue types available in the project instead of excluding these three. Is there something wrong with my script?
I am in a "User" role, but its displaying "Epic," "Enabler," and "Feature"
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
@BaseScript FieldBehaviours fieldBehaviours
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def constantsManager = ComponentAccessor.constantsManager
def allIssueTypes = constantsManager.allIssueTypeObjects
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueTypeField = getFieldById(ISSUE_TYPE)
def remoteUsersRoles = projectRoleManager.getProjectRoles(user, issueContext.projectObject)*.name
def availableIssueTypes = []
if ("Issue Type Visibility Controller" in remoteUsersRoles) {
availableIssueTypes.addAll(allIssueTypes.findAll { it.name in ["Epic", "Enabler", "Feature"] })
}
if ("Users" in remoteUsersRoles) {
def excludedTypes = ["Epic", "Enabler", "Feature"]
availableIssueTypes.addAll(allIssueTypes.findAll { !(it.name in excludedTypes) })
}
issueTypeField.setFieldOptions(availableIssueTypes)
Hi @jira_admin_cu ,
Removing the required Issue types from the project Issue type scheme will not help you ?
Hi @Rilwan Ahmed ,
No, we want to keep the old tickets under those issue types, but prevent the creation of new tickets.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Based on what condition do you intend to hide the issue type?
Is it on the current logged-in user's role or group?
If it is based on the User's Role, you can follow the steps provided in this ScriptRunner Documentation, which is the same approach you are using in the code you have shared.
On the other hand, if it is based on the User's group, you can follow the example that I provided in this community discussion.
I hope this helps to answer your question. :)
Looking forward to your feedback.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_ ,
Thank you for your quick response, as usual!
I want to hide three specific issue types—"Epic," "Enabler," and "Feature"—from hundreds of Jira projects. Each project has different configurations and additional issue types, but my goal is to exclude these three from all users in all projects, with the exception of the "jira-administrators" group. This change should apply across multiple Jira projects, so we can keep browse the old tickets under these issue types, but users can't create new tickets under these issue types.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Apologies for the delay in responding. I was OOO.
For your requirement, I suggest changing your approach to something like this:-
import com.adaptavist.hapi.jira.groups.Groups
import com.adaptavist.hapi.jira.users.Users
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
@BaseScript FieldBehaviours behaviours
def loggedInUser = Users.loggedInUser
def adminGroup = Groups.getByName('jira-administrators')
def issueTypeField = getFieldById(ISSUE_TYPE)
def availableIssueTypes = ['Epic', 'Story', 'Task', 'Bug', 'Sub-task']
if (!loggedInUser.isMemberOfGroup(adminGroup)) {
availableIssueTypes.remove(0)
}
issueTypeField.setFieldOptions(availableIssueTypes)
Please note that the sample working code above is not 100% exact to your environment. Hence, you must make the required modifications.
In the code above, I am using ScriptRunner's HAPI feature to simplify the coding process, eliminating the need to invoke the ComponentAccessor.
As you can see in the code above, I have first hardcoded all the issue types available in the Issue Type field. Next, to filter the issue types according to the Group, I have added an if condition. If the currently logged-in user is not a member of the Jira Administrator Group, they will not be able to create an Epic issue type.
In your use case, if you have multiple issue types that you intend to filter, you must first add them to the list of all available issue types and remove them accordingly by using the remove() method.
Note: you must add this to the Behaviour's Initialiser for it to take effect.
Since you want this Behaviour to work on all projects, select the All project in the Project option as shown in the Screenshot below:-
With the code above, I can confirm the users who are not in the Jira Administrator's Group, will not be able to create the Epic issue type, but are still able to Browse existing Epic issues.
I hope this helps to solve your question. :)
I am looking forward to your feedback.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @jira_admin_cu ,
I suggest to go through this thread: https://community.atlassian.com/forums/App-Central-questions/Hide-Issue-Types-with-ScriptRunner-Behaviors-not-working/qaq-p/2916028
I hope it helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.