How to avoid subtask creation on transition if subtask with certain issue type exists

Hi guys,

i'm trying to auto-create subtasks for issues on certain transitions that meet requirements.

but i don't want them to be recreated if this process has to be repeated. I am using scriptrunner built in script for auto-creating subtask on transition.

I want to create a condition for avoiding the creation for the post function feature 'create subtask' if a subtask with the same issue type already exists.


any help is appreciated


5 answers

1 accepted

1 vote
Accepted answer

so i kind of took a mix of everything.


you can do exactly what i needed using the script that Jonny provided. if you take 

!issue.subTaskObjects.any{ == "The Target Issue Type I want to avoid"
and put it with any other conditions you want you can stop the auto creation of sub tasks, without having to write a bunch of unnecessary code. 

Thanks to all those that helped me figure this out.

So, Vasiliy is almost there. What you could do is create a condition on your post function to determine if any of the subtask objects have the issue type you're concerned about. You'll have to hard-code it, since, as Thanos noted, the value of the drop-down field won't be available to the condition at runtime (at least, not without a lot of hacking).

Something like

!issue.subTaskObjects.any{ == "The Target Issue Type I want to avoid"

If you're leaving the target issue type blank, the function will just default to the same type as the parent issue (assuming that's a valid sub-task type), so you could do something like:

    it.issueType == issue.issueType

do i have to also code in something like. get list of sub tasks to search for the issue type? 

because in a way you don't need to know the value of the target issue type. if you give it the condition of if a sub task with this issue type exists stop process kinda thing. you don't need to tell it to be the same one do you?

or can i simply state 

!issue.subTaskObjects.any{ == "The Target Issue Type I want to avoid"
} and then any other conditions i need?

can things only on the dropdown be done on the create subtask post function then?

Hi Daniel 

I am afraid that this is not possible using the built in create subtasks post function, because in the condition field you cannot know the value of the Target Issue Type field is. 

It will be possible though, using a custom post function.I suppose now you have more that one create sub tasks post functions in the same transition, one for every subtask issue type you want. 

Therefore the single custom post function will merge all the post functions you have plus you will be able to add the condition you mentioned. 

Hope that makes sense, if you need further assistance, ping me.

regards, Thanos

0 votes
Vasiliy Zverev Community Champion Dec 22, 2016

Here is code to loop all subtasks for issue. It stops when issue with specidied issue type name is found

import com.atlassian.jira.issue.Issue

for(Issue subTask: issue.getSubTaskObjects()){

then from here do i just have to write the code on how to create the subtask etc?

any assistance is always helpful so if you have anything you think will be good please send it my way

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,301 views 12 19
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