i wanted to answer to this question but the question was already closed:
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())
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())
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?)?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have the same question as Dianne. Where would we apply the code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.