How should I Restrict sub-task creation until the Parent is in a specific status in Jira Server?
Asked by Utah:

**Scenario:**   
In a project management system like Jira, once a parent issue reaches the "In Development" or later status, regular users should not be allowed to create, remove, or modify any sub-tasks associated with that parent issue. This restriction is necessary to maintain the integrity of the project and prevent unauthorized changes to the task hierarchy.

**Requirement:**   
Develop a feature or script that can enforce the following rules:

1. Users who are not part of the "Administrators" group should not be able to create, remove, or modify sub-tasks for a parent issue that is in the "In Development" or later status.
2. Users who are part of the "Administrators" group should be able to create, remove, and modify sub-tasks for any parent issue, regardless of its status.

**Implementation:**   
The solution should be implemented using a Jira add-on or a custom script that can be integrated with the project management system. The script should:

1. Define the list of issue statuses that should be considered "In Development" or later (e.g., "In Development", "Testing", "Completed", "Closed").
2. When a user attempts to create, remove, or modify a sub-task, check the status of the parent issue.
3. If the parent issue is in the "In Development" or later status, and the user is not an administrator, prevent the action and display an appropriate error message.
4. If the user is an administrator, allow the action to proceed regardless of the parent issue status


Answers:
author: Dick
body: Modification and movement permission of issues (like sub-tasks) are given in the project's permission scheme listed there (click it to get the overview).

cog-wheel - system - issues - left menu: permission schemes - Your Project's Permission Scheme

There, you might want to remove some roles from:

Edit / create / delete / move issues

comments: author: Utah
body: Thank you for your suggestion. However, I only wish to limit it to the specified status, therefore, I shouldn't be able to directly alter the permission scheme.


author: Maciej Dudziak _Forgappify_
body: Hi [@Utah](/t5/user/viewprofilepage/user-id/4833947)

Is this question for Cloud or DC, or both? I see deployment Cloud, but in tags there is 'jira-server'

comments: author: Utah
body: For DC or Server?thanks.


author: Utah
body: I made a mistake, sorry .


author: metin zeynep
body: JIRA: Use JIRA's workflow conditions and validators to restrict sub-task creation based on the parent task's status. For example, you can add a condition to the "Create Sub-Task" transition that only allows it if the parent task is in a specific status.

Asana/Trello: While these tools may not have as advanced workflow automation as JIRA, you can use integrations or custom scripts with tools like Zapier to implement similar logic.

Microsoft Planner/Project: Use Microsoft Power Automate to create flows that manage task creation based on conditions like the status of a parent task.


author: Utah
body: Do you have any good implementation methods? Can it be implemented using Scriptrunner scripts?

comments: author: metin zeynep
body: Yes, Scriptrunner is a powerful tool that can be used to implement custom scripts and automation in Atlassian Jira. You can use it to enforce rules and conditions on issue creation, including restricting sub-task creation based on the status of the parent issue.

Implementing Restriction Using Scriptrunner in Jira

Here's a general approach using Scriptrunner to restrict sub-task creation until the parent task is in a specific status:

1. Identify the Parent Status Requirement

Determine the specific status (e.g., "In Progress," "Approved") that the parent task must have before sub-tasks can be created.

2. Create a Custom Script Validator

You can create a custom script validator in Scriptrunner that checks the status of the parent task whenever a sub-task is being created.

3. Script Example

Below is an example Groovy script for Scriptrunner that restricts sub-task creation unless the parent issue is in a specific status (e.g., "In Progress"):

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.IssueManager

import com.atlassian.jira.workflow.function.issue.AbstractJiraFunctionProvider

import com.opensymphony.workflow.WorkflowException

// Get the issue manager

IssueManager issueManager = ComponentAccessor.getIssueManager()

// Get the parent issue

Issue parentIssue = issue.getParentObject()

// Check if the parent issue exists and is in the required status

if (parentIssue == null \|\| parentIssue.getStatus().getName() != "In Progress") {

throw new WorkflowException("Sub-task creation is restricted until the parent task is in 'In Progress' status.")

}

4. Add the Script to a Workflow Validator

Go to your Jira project's workflow and find the transition where sub-tasks can be created.

Add a "Script Validator" to this transition and paste the script.

5. Testing

Test the workflow to ensure that the validator correctly restricts sub-task creation when the parent issue is not in the required status and allows it when the condition is met.

Additional Considerations

Customization: You can customize the script based on different statuses, projects, or issue types.

User Feedback: Ensure the script provides clear feedback to users when sub-task creation is restricted.

Permissions: Make sure that only authorized users can bypass these restrictions if necessary.

This method using Scriptrunner scripts provides flexibility and control over workflows in Jira. Always test your scripts in a staging environment before deploying them to production to avoid any disruptions


author: Utah
body: Thank you for your response. Currently, the idea I can think of is to use Validators to restrict the creation of subtasks, but how can I restrict the modification and movement of subtasks?


Tags: jira-server