How to delete an issue type from project or hide it from "create issue" screen

mesa sisa June 18, 2020

i wanted to answer to this question but the question was already closed:

https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-delete-issue-type-using-groovy/qaq-p/501207

so i am posting my solution here:

this is how you can remove an issue type (and also add an issue type) from an project.

the cool thing is that the existing issues will not be affected but it is only prevented that users can choose the target issue type in "create issue" screen. works for me with Jira 8.5

please try out if you need that:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.option.OptionSetManager
import com.atlassian.jira.issue.fields.config.FieldConfigScheme
import com.atlassian.jira.issue.fields.option.OptionSet
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.project.Project


def targetissuetypeID = "10001" //story
def projectKey = "MSA"

//get needed components
def itsm = ComponentAccessor.issueTypeSchemeManager
def opsm = ComponentAccessor.getComponent(OptionSetManager)
def pm = ComponentAccessor.projectManager

//set vars with required objects from user input
def proj = pm.getProjectByCurrentKey(projectKey)
def issueTypes = itsm.getIssueTypesForProject(proj)

//get fieldconfig scheme for target project. you should maybe check if scheme is not global so that other projects are not affected
FieldConfigScheme scheme = itsm.getConfigScheme(proj)

//issue types that can be seen in 'create issue' screen are stored as options
OptionSet options = opsm.getOptionsForConfig(scheme.getOneAndOnlyConfig())
def newoptionsArray = []
newoptionsArray = options.getOptionIds()

//remove target issue type
newoptionsArray.remove(targetissuetypeID)
itsm.update(scheme, newoptionsArray)

//add an existing issue type to project
//options.addOption(IssueFieldConstants.ISSUE_TYPE, targetissuetypeID)
//itsm.update(scheme, options.getOptionIds())

 

2 answers

1 accepted

1 vote
Answer accepted
mesa sisa June 24, 2020

this is how you can remove an issue type (and also add an issue type) from an project.

the cool thing is that the existing issues will not be affected but it is only prevented that users can choose the target issue type in "create issue" screen. works for me with Jira 8.5

please try out if you need that:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.option.OptionSetManager
import com.atlassian.jira.issue.fields.config.FieldConfigScheme
import com.atlassian.jira.issue.fields.option.OptionSet
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.project.Project


def targetissuetypeID = "10001" //story
def projectKey = "MSA"

//get needed components
def itsm = ComponentAccessor.issueTypeSchemeManager
def opsm = ComponentAccessor.getComponent(OptionSetManager)
def pm = ComponentAccessor.projectManager

//set vars with required objects from user input
def proj = pm.getProjectByCurrentKey(projectKey)
def issueTypes = itsm.getIssueTypesForProject(proj)

//get fieldconfig scheme for target project. you should maybe check if scheme is not global so that other projects are not affected
FieldConfigScheme scheme = itsm.getConfigScheme(proj)

//issue types that can be seen in 'create issue' screen are stored as options
OptionSet options = opsm.getOptionsForConfig(scheme.getOneAndOnlyConfig())
def newoptionsArray = []
newoptionsArray = options.getOptionIds()

//remove target issue type
newoptionsArray.remove(targetissuetypeID)
itsm.update(scheme, newoptionsArray)

//add an existing issue type to project
//options.addOption(IssueFieldConstants.ISSUE_TYPE, targetissuetypeID)
//itsm.update(scheme, options.getOptionIds())

Dianne M Fry-Bolton August 31, 2021

Hello, @mesa sisa. This looks like something I would like to do.  Where would this bit of code go (i.e., how do I make it render?)?

Wansze Kong December 20, 2022

I have the same question as Dianne.  Where would we apply the code?

0 votes
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 22, 2020

Hi,

Thanks for posting a solution to this question.  However right now we can't accept the answer you posted, because it's in the question.  

Would you mind posting the solution portion as an answer to this question (and not as a reply to my answer here)?   That way you can accept your own answer.  This has an added benefit that it can help this post appear as 'solved' in search results, which makes it easier for others to find.

Thanks

Andy

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events