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

Daniel Tombs December 21, 2016

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

1 vote
Answer accepted
Daniel Tombs January 16, 2017

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.
2 votes
Jonny Carter
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 23, 2016

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
}
Daniel Tombs January 16, 2017

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?
Daniel Tombs January 16, 2017

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

0 votes
Daniel Tombs December 23, 2016

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

0 votes
Vasiliy Zverev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 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; 
}
Daniel Tombs December 23, 2016

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

0 votes
Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 21, 2016

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

Suggest an answer

Log in or Sign up to answer