Jira Automation: How to make Epic status change by percentage of completed stories of epic
Asked by Jonathan Chatfield:

Hello,

I have automated the process of story's status automatically changed at a certain percent of completed of sub-tasks status to Done. I am now looking at automatically updating the epic status progress from the completion of percentage of the automated story status with Done to change the Epic status to In Progress then after all the automated stories statuses are in Done Status then put the Epic status to Done status as well. My To Do status category is Backlog.   
![example.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/322438i6ED8C22FF8E00501/image-size/large?v=v2&px=999 "example.jpg")This is a project plan so we are going to have every task be a sub-task and those tasks live in Stories then every story is under a umbrella of a epic. Here is a example of that setup!   

I do not have the function LookupIssue and I have been told that I will need to do a process that uses REST API. I do not know much about this process but I am excited to hear from anyone out there! =D


Answers:
author: Bill Sheboy
body: Hi [@Jonathan Chatfield](/t5/user/viewprofilepage/user-id/5489117)

You describe your automation rules do not have the Lookup Issues action; thus I am guessing you have Jira Server, correct?

If so...

First thing, please write some JQL which returns the child (and grandchild) issues for an epic, without returning the epic itself.

Then your rule could use the Send Web Request action to call the REST API issue search with that JQL. Here is a how-to article for that technique and the issue search function documentation.

* <https://community.atlassian.com/t5/Jira-Software-articles/Automation-for-Jira-Send-web-request-using-Jira-REST-API/ba-p/1443828>
* <https://docs.atlassian.com/software/jira/docs/api/REST/9.13.0/#api/2/search-search>

When you have the response, you could use math expressions and smart value, list filtering to get the percentage from the count "done" / total count.

* <https://confluence.atlassian.com/automation/jira-smart-values-math-expressions-993924866.html>
* <https://community.atlassian.com/t5/Automation-articles/Filtering-smart-value-lists/ba-p/1827588>

Kind regards,  
Bill

comments: author: Jonathan Chatfield
body: Hello [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

We have finally gotten a new version of Jira and we have lookup action and variables. Can you show me a pathway of how to make epics automatically update based off the percentage of Story's status marked Done.


author: Bill Sheboy
body: No problem; glad to help! FYI...I am using Jira Cloud so please verify / test to confirm this works for your version of Jira.

The technique below uses the math expressions and list filtering I noted earlier. Let's assume you want to update the percentage "Done" whenever the status of a child issue changes, and the percentage value will be stored in a custom field in the Epic. Please adjust accordingly if those assumptions are incorrect.

* trigger: issue transitioned
* condition: issue type is Story, Task, Bug, or any of the types you have as children of your Epic
* branch: to Epic parent
  * action: lookup issues, with JQL of: "Epic Link" = {{issue.key}}
  * action: update the parent's custom field with the result of this expression

```
{{#=}}ROUND( ( 0{{#lookupIssues}}{{#if(equals(status.name,"Done"))}}+1{{/}}{{/}} ) / {{lookupIssues.size|0}} * 100, 0){{/}}
```

How that works...

1. while iterating over the issues in the lookup result
2. filter on the ones with a status of "Done", adding +1 for each of those
3. and wrapping that in parentheses with a default value of 0 at the front
4. divide that by the total count of issues in the lookup
5. multiply by 100 and ROUND to the percentage is a whole number
6. finally wrapping all of that in a math expression.

That percentage is by **count** . If instead you want the percentage based on **Story Points**, try this one:

```
{{#=}}ROUND( ( 0{{#lookupIssues}}{{#if(equals(status.name,"Done"))}}+{{Story points|0}}{{/}}{{/}} ) / {{lookupIssues.Story points.sum|0}} * 100, 0){{/}}
```


author: Jonathan Chatfield
body: Thank you for responding back to me! I am currently working on this and I will try what you are writing.

I do not want my team to be touching stories and above as we will only edit Sub-tasks. I have a automation that will automatically update stories from the percentage of Done statuses from Sub-Tasks.   
Will this automation still be triggered if I put story if it didn't get triggered by me but by a automation?


author: Bill Sheboy
body: By default, automation rules do not trigger due to actions from other rules. This is to prevent errors / runaway looping.

When you intentionally want the actions of one rule to trigger another, in the *downstream rule*, go to the rule details and enable the option "Allow rule trigger..." Then test thoroughly and monitor for any problems.


author: Jonathan Chatfield
body: Yes! Thank you so much, it worked!!


author: Dave Rosenlund _Trundl_
body: Hi, [@Jonathan Chatfield](/t5/user/viewprofilepage/user-id/5489117). I'm *not* a developer myself, but I do have some getting-started tips for you:

* I'm told [Atlassian's documentation for REST APIs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#about) is very good.
* Also, Atlassian has a [dedicated developer community](https://community.developer.atlassian.com/) that you can join.

Hope it helps,

-dave


Tags: jira-core

rest-api