How can I transition the parent when all subtasks are resolved with Automation for JIRA?
Asked by andreas:

Using [Automation for JIRA](https://marketplace.atlassian.com/plugins/com.codebarrel.addons.automation/) is it possible to transition the parent when all subtasks are resolved?  
[](https://community.atlassian.com/t5/Automation-questions/How-can-I-transition-the-parent-when-all-subtasks-are-resolved/qaq-p/159407?attachment-id=12376){#link_115db40fba93a4}  
[](/tnckb94959/attachments/tnckb94959/automation-questions/116/1/transitionparent.png){#display_115db40fba93a4_0}  
[](https://community.atlassian.com/t5/Automation-questions/How-can-I-transition-the-parent-when-all-subtasks-are-resolved/qaq-p/159407?attachment-id=12377){#link_115db40fba93a4_0}  
[](/tnckb94959/attachments/tnckb94959/automation-questions/116/2/Screen%20Shot%202017-02-02%20at%2018.24.36.png){#display_115db40fba93a4_2}  
[](https://community.atlassian.com/t5/Automation-questions/How-can-I-transition-the-parent-when-all-subtasks-are-resolved/qaq-p/159407?attachment-id=12378){#link_115db40fba93a4_1}  
[](/tnckb94959/attachments/tnckb94959/automation-questions/116/3/Screen%20Shot%202017-02-02%20at%2011.20.50.png){#display_115db40fba93a4_4}  
[](https://community.atlassian.com/t5/Automation-questions/How-can-I-transition-the-parent-when-all-subtasks-are-resolved/qaq-p/159407?attachment-id=12379){#link_115db40fba93a4_2}  
[](/tnckb94959/attachments/tnckb94959/automation-questions/116/4/Screen%20Shot%202017-02-02%20at%2011.26.15.png){#display_115db40fba93a4_6}


Answers:
author: andreas
body: This is definitely possible using the related issues [action](https://codebarrel.io/available-rule-components#related-issues) and [condition](https://codebarrel.io/available-rule-components#related-condition):

![Project automation - Code Barrel JIRA 2017-01-03 16-54-19 (2).png](https://community.atlassian.com/t5/image/serverpage/image-id/723iCEC8D6F103CE27AE/image-dimensions/501x441?v=v2 "Project automation - Code Barrel JIRA 2017-01-03 16-54-19 (2).png")

Lets break this rule down:

* Trigger: When any issue in this project is transitioned
* First check using the 'Compare' condition that it was a 'Sub-task'. You could also use a JqlCondition here too.
* Then: We use the related issues action to branch the rule for the 'Parent'
* And on this branch we use the 'Related issues condition' to check that all sub-tasks of the parent match 'status = Done'
* Finally if that condition is true, then the 'Transition Action' will transition the parent to 'Done'

[](https://community.atlassian.com/t5/Automation-questions/How-can-I-transition-the-parent-when-all-subtasks-are-resolved/qaq-p/159407?attachment-id=9403){#link_115db415758de3}  
[](/tnckb94959/attachments/tnckb94959/automation-questions/117/1/Project%20automation%20-%20Code%20Barrel%20JIRA%202017-01-03%2016-54-19.png){#display_115db415758de3_0}

comments: author: Russ Watson-Thomas
body: Hey Andreas,

Just expanding on this a little bit... I use multiple different subtask types. Is this powerful enough to differentiate? i.e. I can pick the subtask type I want to compare and then trigger a parent transition (and or do this via a filter searching for those subtaskIssueTypes())?

If so, that's incredibly powerful for me! :smile:


author: andreas
body: Hey Russ,

Yes you can certainly do more filtering. We don't support else statements yet, so right now you'd have to setup multiple rules.

In the rule shown above you'd simply insert another condition **before** the "Then: For Parent" action. You could use a JQL condition for example to test "type = myspecialsubtasktype" (or any JQL really). If the sub-task that was transitioned matches then the rule will continue and transition the parent. If it doesn't then rule execution will stop.

You can also add more conditions in the "Then: For Parent" branch to for example only transition the parent if **it** is of a specific type/JQL match.

Setting up multiple rules is simple - you can just got to 'Create rule' -\> 'Copy rule' to copy an existing rule if you just want to change the condition. We'll add proper 'else' support in future but for now this should work as well.

If you can describe a more specific example I'm happy to provide an example rule as well.

Cheers,

Andreas


author: Russ Watson-Thomas
body: Hey Andreas,

Thank you for the reply, it's massively useful. Here is a full on use case:

1) I have multiple subtasks (i.e. Dev Task, Test Task, Documentation)

2) Each has it's own workflow

3) Parent's have their own workflow

Use Case:

Update Parent from Waiting for Dev to In Dev when any Dev Task is not new

Current thought: One automation rule that says Transition Parent to In Dev when JQL filter says dev tasks status is not new

Update parent to waiting for test when dev tasks are closed

Current though: another rule that says transition parent to Waiting for Test when JQL filter says all dev tasks closed

I guess the bit I find a little tricky right now is iterating over multiple subtasks to say 'all in status' .. but it looks like there's a rule in the compare bit that does this.. Could you help clarify this for multiple different task types? Just multiple rules?


author: andreas
body: Hey Russ,

So you can do this as separate rules, or you can do it in a single rule as well. Here's an example:

transitionparent.png

So what I have is 2 related issues actions 'For parent' with a related issues condition that uses JQL to find all sub-tasks of a given type *parent = {{ issue.key }} and type = "Dev-task"* and then checks if some of them are in progress, or all are done respectively.

If some are in progress, I transition the parent issue to "In Progress". If all are Done I transition the parent issue to "Waiting for deploy" (in your use case this would be the "Waiting for test" status, but I didn't want to edit my workflow as well - you get the idea :smile: ).

Hope this makes sense!


author: andreas
body: Hey everyone,

Just letting you know that with the latest release of Automation for JIRA this is now a bit easier:  
<https://blog.codebarrel.io/better-transitions-and-simpler-scheduled-triggers-90b4b991b778>

The improved Transition action now also supports smart-values and some special values like 'Copy from issue', 'Copy from Epic' etc.

Cheers,  
Andreas


author: Dimitri Zetzsche
body: I already mailed this to @Andreas Knecht, it's maybe useful for someone else who is looking for the answer:

**My use case**

I want to close User Stories when all Linked issues are closed. The difference with the example in this threadis that I have linked issues instead of sub-task. I thought it wouldn't be a problem since the *related issue condition* supports *Linked issues.*

**I have following test case set up:**

* USER story HOR-938 with status = open
  * contains (= issue links) HOR-939 ( issuetype = task, status = open)

When I transition HOR-939 to status Closed I see in the audit log that the flow triggers but returns an error. Maybe I misunderstand something in the JIRA architecture but:

* HOR-939 has a parent
* The parent is a user story which has linked issues.

Screen Shot 2017-02-02 at 11.20.50.png

**My workflow**

Screen Shot 2017-02-02 at 11.26.15.png

++EDIT:++

I tried the same with now using the concept of "sub-tasks" and it works fine. However I wonder if it would also work with "linked issues". Maybe my use case with linked issue fails because there is no "parent-concept" with linked issues?

++EDIT2:++

I managed to get it working with *linked issues* . Like I already mentioned in my first EDIT with linked issues there is no *parent* concept. I took a different approach in my automation flow:

Screen Shot 2017-02-02 at 18.24.36.png

Cheerio

Dimitri


author: andreas
body: Hey Dimitri,

Nice work! Yes, for linked issues the 'Related issues' action needs to use 'linked issues'. The parent and sub-task options only work for those types of relationships.

Cheers,

Andreas


author: phil huynh
body: Hi Andreas,

Im trying to do something similar. above you wrote...

So what I have is 2 related issues actions 'For parent' with a related issues condition that uses JQL to find all sub-tasks of a given type parent = {{ issue.key }} and type = "Dev-task" and then checks if some of them are in progress, or all are done respectively.

I dont understand the part where you sday check if all are done. I dont see how you check if all the returned jql items are done. Im to the part where i can select my subtasks of certain type. But i dont see how to run the condition against the returned subtasks. Im probably overlooking something simple.


author: andreas
body: Hey Phil,

So what you need is a 'Related issues condition'. It allows you to check if any, all or no issues match a given JQL.

See <https://codebarrel.io/available-rule-components#related-condition>

So you could use this to check if **all** sub-tasks of a given type match:

```
parent = {{issue.key}} and type = "Dev-task" and status = Done
```

Hope that makes sense!

Cheers,

Andreas


author: KS
body: Hello,

maybe someone can help. I have a task with many sub-tasks. I need to transition task to status Closed once all sub-tasks are closed.

I reproduced the automation rule provided at the very beginning (Project automation - Code Barrel JIRA 2017-01-03 16-54-19.png ?278 KB), but still that doesn't work. I get error: Error searching for related issues. This is most likely because the following issues don't have a related issue of the type you specified. Try narrowing your search to only include issues that contain links to related issues:  
API-942

Please advice


author: andreas
body: Hi Krystsina,

Can you post a screenshot of your rule showing the 'related issues' action configuration please?

You can also do this in support via <https://codebarrel.io/support> if you don't want to post your rule publicly here.

Cheers,

Andreas


author: KS
body: Hello Andreas,

please find screenshot below.

![automation.png](https://community.atlassian.com/t5/image/serverpage/image-id/551i8245437CB0027797/image-size/large?v=v2&px=999 "automation.png")


author: andreas
body: Hi Krystsina,

This should work I think. Lets move this to <https://codebarrel.io/support> please - I don't want to dillute the question here with providing support.

Can you raise a support request please, and include screenshots with your audit logs as well, showing what went wrong?

Can you also include screenshots of the issue that was transitioned, showing its 'History' tab please?

Cheers,

Andreas


author: KS
body: Hello Andreas,

I found an issue. It seems that in case you have transition 1-\>2-\>3 it won't allow you to automatically go from 1 to 3. You have to automate 1-\>2 and 2-\>3

Thanks!


author: Vrushali Yewle
body: Hi Andreas

How do I know that the syntax for saying "issuetype = sub-task" is {{issue.fields.issuetype.name}} = Sub-task? How do I know that is isn't just {{issue.issuetype}} = Sub-task? Is there a syntax manual? I went through your documentation but I did not find an exhaustive list.

I can always use JQL, of course. But this mustache syntax has me curious.


author: andreas
body: Hey Vrushali,

So <https://codebarrel.atlassian.net/wiki/spaces/AUTO4J/pages/27656216/Smart+Fields> is the best place to look for this currently.

It isn't an exhaustive list as you mentioned though. It's kind of hard to compile such a list, due to sheer number of different field types and field attributes available in Jira.

If in doubt I'd say use a JQL condition. We do have plans to make smart-values easier in the product in future through some sort of autocomplete (<https://codebarrel.atlassian.net/browse/AUT-104>).

Cheers,  
Andreas


author: Jimmy
body: Hi Andreas,

I posted the following 2 questions as a comment on your Medium post but I just found this thread too so I'll paste them here as well.

I'm a new JIRA Core (Cloud) user and Automation for JIRA user. The " Related Issues" condition looks pretty awesome and seems like what I'm looking for. I have 2 questions:

1. I'd like my Sub-Tasks to All match specified JQL where (in pseudo-code) "status is equal to *any type of Done value* ". And by that, I mean that in JIRA, if I understand correctly, there's the default "Done" status, but also a bunch of "Done" equivalents, such as (a) the system built-in ones "Closed", "Resolved", and (b) custom statuses that I've defined and mapped to the system Done state. How do I specify the JQL to match either all of set (a) or all of set (b) or both sets (a) and (b)? Maybe something like `status in (Done,Closed,Resolved,myCustomDoneStatus1,myCustomDoneStatus2)`?
2. Just to further complicate matters, I've translated some statuses to Chinese. Does JQL in general match the translated values or just the original values, or both? What if my original value of a custom status was not entered in English but directly in Chinese (and thus does not have a translated value, but just has an original value that's non-English)? I would hope that JQL in general matches the original non-translated value, and is able to match international character sets?---?would just like to confirm this behaviour.

Hope that my questions are clear enough. Thanks!


author: andreas
body: Hi Jimmy,

I just posted a reply on Medium: <https://medium.com/@kandreas/hi-jimmy-9d100c94bd2b?source=post_info_responses---------4---------------->

Cheers,

Andreas


author: Jimmy
body: Thanks! statusCategory = Done was exactly what I was looking for. I also didn't know there was an issue navigator, indeed very useful for building and testing JQLs.


author: Marcelo Ignacio Cid Abud
body: Hi [@andreas](/t5/user/viewprofilepage/user-id/853524)

I need your help

How can I do this automation in the opposite case? That is, when the history passes to the discarded state, all the subtasks (that were in progress) are moved to discarded and those that were in the backlog are eliminated?


author: Srikanth Mamidala
body: Please ignore my earlier message, I was able to figureout what was wrong. Its my mistake . This raises another question for me is that

Can we include multiple subtasks inthe "Second value" option of the if condition?

My end goal is, when someone creates a issue and transition to a 1st status, it needs to create multiple subtasks, and when all the subtasks are complete it should move to next status where another bunch of new tasks are created and when subtasks are closed again move to next status and so on.

I was successful in using automation for this and tested with one subtasks at one transition using this, but I would hate to create multiple conditions. I could use special string for all sub tasks and use contain option in if compare.

Just wanting to know what the best recommended approach/solution to achieve this.

![second.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/89012i042C35DF3E2CDF29/image-size/large?v=v2&px=999 "second.PNG")


author: Srikanth Mamidala
body: Hi Guys,

I am trying to achieve the same thing in question with no success. Attached is the rule, I am not sure if I am doing it wrong because from the first screenshot which andreas posted, mine doesnt look same

1. I could not find compare 2 values option but mine just says match 2 option

2. It doesnt let me add a new action of the parent at the same root after I used if statement

I am not sure if anything has changed with regard to the version I am using.

Please advise. ![JIra.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/89008i969679A6EF4C1881/image-size/large?v=v2&px=999 "JIra.PNG")


author: Zehra Atmaca
body: Hi all,

I am struggling in automating to automatically close the parent if all linked issues via link type "Forwarded" are Resolved.

I've already tried with JMWE and Automation for jira but unfortunately without results...

Have somebody experience with that?

Any idea will be welcome

Thanks

Kind regards

comments: author: Michele VS
body: Using Subtask (Test Executions) for Parent Use Test Cases

Automation seems to work and I receive notification but parent status isn't updated as soon as all subtasks are Passed.. seems to be a delay. I need to either refresh screen or exit to see the parent Use Test Case status updated to Passed.

Using this rule because testers forget to update parent when all tests are passed


Tags: addon-com.codebarrel.addons.automation

addon-com.codebarrel.addons.automation.lite

jira