prevent subtask creation/issue creation. Edited

Hi Team,

i need help for few of my questions and if its possible then how to implement them .

In JIRA workflow for my client ,i have created grrovy script that creates subtask when parent issue is created but now i wanted to add some constraints when a manual subtask is being created for a parent issue.

1. if autocreated subtask exists with same summary then manually new subtask  should not be created.

2. if my parent issue is makred to done then also it should not allow to create a new subtask manually.

3. parent issue is marked to done, once all subtasks are done then subtasks should not be allowd to move into other status even if transition from done to inprogress does exist.


Kinldy provide some code or scripts that can help me achiving above mentioned points.


Thanks in advance !

1 answer

1 accepted

Hey there, I think I have a viable solution for each of your requests. So I'll go through each one-by-one:

1. For your first requirment, it would be easiest to hide the Create-Subtask UI element using one of the built in Script Fragments. You can find these by pressing the "." (period) key while in your JIRA instance and searching for "Script Fragments." The fragment that you want to add is "Hide system or plugin UI element." Once you are in the creation screen for that fragment, add this code to the "Condition" block:


def currentStatus =

!(currentStatus == "Done")

And select the create-subtask element from the web-items to hide. The code states that if an issue is in the "Done" status, then the Create-Subtask option will not appear on the issue view screen. Additionally, if you would like to do more than just remove the option from view, you can add a script validator to the Create transition, similar to the route I take below.

2. For your second requirment, you need to make a simple script validator on the Create transition in your workflow (if you need assistance in setting that up, let me know). The condition you use should look something like this:

    def issueParent = issue.getParentObject()
    def parentSubTasks = issueParent.getSubTaskObjects()
    def currentSubTaskSummary = issue.getSummary()
    !parentSubTasks.find{it.getSummary() == currentSubTaskSummary}

This condition checks every other subtask assigned to its parent issue and ensures that the subtask being created is not a duplicate. Add an appropriate error message and leave the Field box blank (make sure you publish the workflow after adding the validator).

3. For your third requirment, you need to add another workflow validator to every transition that is not your "Done" transition. I wasen't quite sure what you were asking for in the third point, so this is what I came up with:

    if(issue.getParentObject() == "Done")
        ! == "Done"

This condition essentially makes it so that a subtask cannot transition to the status associated with this validator if its parent's status is set to "Done." Again, add the appropriate error message and leave the Field box blank. Just to reiterate, this validator must be added to every transition that is not your "Done" transition to ensure that a subtask cannot be set to any of those statuses.

That's all I've got! Let me know if you need help or further clarification with any of this!





Hi Aiden - i have similar need for the first one but instead of stopping manual sub-task from being created, i want to stop a duplicate from being created on the transition (if the workflow went back a step and then forward again).

any ideas on this one? 



Hey Tracey!

Assuming you are using the Create Subtask SR post-function, you should be able to use a condition like this to check if the issue already has a subtask with the given summary:

import com.atlassian.jira.component.ComponentAccessor

def subtasks = issue.subTaskObjects
if(subtasks.find{it.summary == "Subtask Summary"})
return false
return true

Suggest an answer

Log in or Join to answer
Community showcase
Alexey Matveev
Published Saturday in Jira

How to run Jira in a docker container

Everything below is tested on Ubuntu 17.10. I prefer to use Jira in a docker container because: 1. I can install Jira with a couple of commands. 2. I can start and stop Jira just by starting and s...

130 views 3 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot