Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Need to hide issue types from issue type drop down

Garden16 January 7, 2022

I have two sub task types - Subtask and Defect subtask . The Defect subtask is  for Bug issue  and Sub-task is  for all other issue type. When ever I click On the Create subtask screen , both  Sub task and Defect  issue type get populated from the Issue type drop down. I  would like to  hide the Sub task and make it Defect when  I  create a defect subtask under the Bug issue type.

 

 create bug issue type-> click on the create a sub task-> Create sub task screen is displayed. In the drop down on the Create subtask screen I see sub task and defect sub task both. I have tried to hide the sub task .But I am not able to. If I make defect subtask read only using the behavior plugin, it is affecting all other Create subtask screen for other issue types(EPIC , User story , task). How do I handle this in Create sub task screen.

Is there a way to create new create subtask screen for Defect subtask (issue type)

 

1 answer

Suggest an answer

Log in or Sign up to answer
1 vote
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 7, 2022

Hi

Welcome to the Atlassian Community.

I don't think you need to build new screens etc.

You can use behaviour to manipulate the list of issue types offered  in the drop down.

The trick is that you need to get information about the parent issue (to know which issue type to show or hide).

And you'll want to make sure that the behaviour only fires when a sub-task is being created (not the parent issues).

Try something like this (in the initializer of a behaviour for your project either mapped to all issue types or just the 2 sub-tasks)

import com.atlassian.jira.component.ComponentAccessor

if(issueContext.issueType.isSubTask()){ //this may not be needed if the behaviour mapping is only for the sub-tasks
def issueTypeField = getFieldById('issuetype')
def parentIssueIdFld = getFieldById('parentIssueId')
def parentIssue = ComponentAccessor.issueManager.getIssueObject(parentIssueIdFld.value as Long)
def allIssueTypes = ComponentAccessor.constantsManager.allIssueTypeObjects

def subtaskName

if(parentIssue.issueType.name == 'Bug'){
subtaskName = 'Defect'
} else {
subtaskName = 'Sub-task'
}
issueTypeField.setFieldOptions(allIssueTypes.findAll{it.name == subtaskName})
issueTypeField.setFormValue(allIssueTypes.find{it.name == subtaskName}.id)
}
Garden16 January 9, 2022

Thank you this code actually worked. It tested it further and added a new subtask by name ' Test Sub-task' , I went ahead and created a create subtask under bug issue type and on the create sub task screen , under the Issue type drop down , I was able to select  the Newly created 'Test Sub-task' from the Issue type drop down. I believe any time a new subtask is added , The new subtask will be displayed under the issue type drop down. How do I handle this issue in future any time a new subtask type is added. 

I would like Bug issue type(Parent issue) to have only  'Defect' Sub task associated with it all the time even if a new Subtask like ' Test Sub- task ' created.

I have hidden behavior to  'Sub-task' subtask in the Script runner  UI Hide element behavior.

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 9, 2022

If you want defect for Bug and all-but defect for non-bug, then the flow of the script could look a little like this:

def allowedSubtasks = []
if(parentIssue.issueType.name == 'Bug'){
allowedSubtasks = allIssueTypes.findAll{it.name == 'Defect'}
//since there is only 1 available subtaks, might as well select it
issueTypeField.setFormValue(allowedSubtasks[0].id)
} else {
allowedSubtasks = allIssueTypes.findAll{it.name != 'Defect'}
}
issueTypeField.setFieldOptions(allowedSubtasks)
Oswaldo Peña Perilla October 10, 2022

Garden16,

How to add more subtasks to the code? I try to add one more subtask with another name and I can't.

TAGS
AUG Leaders

Atlassian Community Events