Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Hide Sub-tasks Issue type

Prabakaran P December 12, 2022

Hi Team, 

I want to hide the other(Not related) sub-task while creating the sub-task. 

Eg: Subtask.jpg

I have two Main task issue types & the sub task issue types.

  • Task
    • Sub-task 
  • Documentation 
    • Sub-Documentation 

If I want to create a sub issue for Documentation I don't want to see the Sub-task issue type, Same for Task. 

Is there any possibilities to do with Script Runner/other options? 

 

Thanks, 

Prabakaran. 

1 answer

2 votes
Fabio Racobaldo _Herzum_
Community Champion
December 12, 2022

Hi @Prabakaran P ,

you can implement that using ScriptRunner - Behaviour (https://docs.adaptavist.com/sr4js/latest/features/behaviours).

 

Map the following behaviour to all issue types within your project and try this code into the initializer :

 

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor;

IssueManager issueManager = ComponentAccessor.getIssueManager();
def parent = getFieldById("parentIssueId");
String issueType = issueContext.issueType.name;

//SUBTASK MANAGEMENT
if(parent!=null) {

  Long parentIssueId = parent.getFormValue() as Long;
  Issue parentIssue = issueManager.getIssueObject(parentIssueId);
  if(parentIssue!=null){
    String parentIssueType = parentIssue.getIssueType().getName();
    def allIssueTypes = ComponentAccessor.constantsManager.allIssueTypeObjects;
    def availableIssueTypes = [];
    if(parentIssueType.equalsIgnoreCase("Task")) {
      availableIssueTypes.addAll(allIssueTypes.findAll { it.name in ["Sub-task"] });
    } else {
      availableIssueTypes.addAll(allIssueTypes.findAll { it.name in ["Sub-Documentation"] });
    }
    def issueTypeField = getFieldById(com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE);
    issueTypeField.setFieldOptions(availableIssueTypes);
  }

}


Hope this helps,

Fabio

Rahul Savaikar
Contributor
January 20, 2023

Thanks @Fabio Racobaldo _Herzum_ - this works well!

Upvoted! :) 

Suggest an answer

Log in or Sign up to answer