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

Dan

5 answers

1 accepted

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{
    it.issueType.name == "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{
    it.issueType.name == "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:

!issue.subTaskObjects.any{
    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{
    it.issueType.name == "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 vote
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()){
    if(subTask.getStatusObject().getName().equals("issueTypeName"))
        return; 
}

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

64 views 0 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