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

Andreas Knecht Community Champion Jan 02, 2017

1 answer

1 accepted

This is definitely possible using the related issues action and condition:

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'

 

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

Andreas Knecht Community Champion Jan 10, 2017

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

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?

Andreas Knecht Community Champion Jan 17, 2017

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!

Andreas Knecht Community Champion Jan 22, 2017

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 

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

Andreas Knecht Community Champion Feb 02, 2017

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

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.

Andreas Knecht Community Champion Apr 04, 2017

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

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

Andreas Knecht Community Champion Apr 20, 2017

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

 

Hello Andreas,

please find screenshot below.

automation.png

Andreas Knecht Community Champion Apr 25, 2017

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

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!

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.

Andreas Knecht Community Champion Oct 03, 2017

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

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!

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.

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 Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

172 views 0 4
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