Building automation that preform action based on child ticket progress
Asked by Gilad Waldman:

I would like to create an automation that triggers on schedule, filters with JQL relevant Epics or Stories (Simple query on a specific field) and per each, it calculates:

* For Epic
  * IF Completion percentage (based on completed child issues SP) \>= 50% then create tasks in a different Project
* For Story
  * IF status = (In progress OR In review OR Deployed OR Done) then create tasks in a different Project

looking at a previous discussion (<https://community.atlassian.com/t5/Jira-questions/Automation-Rule-calculate-progress-based-on-children-of-linked/qaq-p/2159555>) led by [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) i still wasn't clear how to use the suggest smart value  

Thanks..!


Answers:
author: Bill Sheboy
body: Hi [@Gilad Waldman](/t5/user/viewprofilepage/user-id/5405912)

I see two things with what you show:

1) There is no Lookup Issues action in your rule to gather the issues.

2) The expression you show is missing the closing parenthesis and digits for the [ROUND function](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/#Functions). In [my original post](https://community.atlassian.com/t5/Jira-questions/Re-Re-Automation-Rule-calculate-progress-based-on-chi/qaq-p/2159638/comment-id/552720#M552720), I showed this:

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

Kind regards,  
Bill

comments: author: Gilad Waldman
body: Thanks [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) !

Although made these two modifications and don't get any error, the sum I get is "0".

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

Formula was fixed with your help :

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

And for this epic, i have 2 child issues, each has 3 SP - One is "done" and one "To do" so i was expecting to get "3" (or 50%)


author: Bill Sheboy
body: Please post an image of the audit log details showing the rule execution. That may provide more context for what you are observing. Thanks!


author: Gilad Waldman
body: ![Screenshot 2024-09-12 093152.png](https://community.atlassian.com/t5/image/serverpage/image-id/346971iFECFD02A09CD2661/image-size/large?v=v2&px=999 "Screenshot 2024-09-12 093152.png")

Does that helps?


author: Dick
body: Thanks Bill, for stepping up. This surely helps.

:)


author: Bill Sheboy
body: Gilad, what type of project are you using: Company-managed or Team-managed? You may find that information in the project list or at the bottom-left of the screen expanding area.

Why that matters...

Company-managed projects use the *Story points* field, and Team-managed projects use the *Story point estimate* field (even though they are both called "Story Points" in the UX).

If using a Team-managed project, please update the expression to use the other smart value and re-test. Also note smart values are case-sensitive, to please check that also.


author: Gilad Waldman
body: :/ The project is Company-managed.... i wonder what could be the issue...

From the logs it looks like the lookup manage to run on the tickets, and although each of the tickets has SP (3+3) it does not reads it....

[@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) / [@Dick](/t5/user/viewprofilepage/user-id/4586768) any other ideas on what could go wrong?


author: Bill Sheboy
body: Let's try some writes to the audit log to diagnose this...

Please add an action to write to the audit log after the Lookup Issues action, then re-test:

```
looked up issues and story points: {{#lookupIssues}}{{key}}: {{Story points}} points; {{/}}
```

Based on what you described, that should produce something like this:

```
IL-46268: 3 points; IL-37207: 3 points;?
```

Please post an image of the audit log after you run the test.


author: Gilad Waldman
body: ![Screenshot 2024-09-12 201737.png](https://community.atlassian.com/t5/image/serverpage/image-id/347187i2B348913ECB3A112/image-size/large?v=v2&px=999 "Screenshot 2024-09-12 201737.png")

[@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) Yes, this is the case indeed


author: Bill Sheboy
body: Great! Now let's update that audit log write to include the status information to observe if they are filtered out:

```
looked up issues: {{#lookupIssues}}{{key}}: {{Story points}} points in {{status.name}} ({{status.statusCategory.name}}); {{/}}
```

Hold on...I just reviewed your earlier post and it is missing the story points field! Please post an image where you are using this expression:

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


author: Gilad Waldman
body: Boom!!

That worked!!

Apologize on the back and forth and for missing that part, this formula is a bit confusing...

Thanks a lot!


author: Bill Sheboy
body: Awesome; I am glad to learn that helped!

And...I recommend pausing to understand how that expression works, perhaps re-reading the original thread description, and then explain the rule to a teammate. Doing so will help with rule maintenance / improvements in the future.


author: Gilad Waldman
body: 100% will do that. thanks.


author: Dick
body: Hi Gilad,

Which part is giving you a headache?

{{#=}} Start a calculation

ROUND((0+ Round the number function

{{#lookupIssues}} Iterate over the issues looked up by a jql statement

{{#if Start a conditional statement

(equals Look for equal parts A and B

(status.statusCategory.name Part A, the status of the looked-up issue under investigation

,"Done") Part B, is the status equal to Done

)}} Conditional statement is finished, could be true or false

Conditional is true, do the following

{{Story points\|0}} Read the issue's story points. if that's empty, use zero

+{{/}}{{/}}0) Ends the if when conditional is false, add zero

/{{lookupIssues.Story points.sum\|0}}\*100 Sum up the story points of all issues (if sp is null use zero)

,0) give zero as an answer for this issue if the denominator is zero

{{/}} End the calculation

comments: author: Gilad Waldman
body: Thanks [@Dick](/t5/user/viewprofilepage/user-id/4586768) for the clarification. ill be more specific

Im getting this error: Mismatched parentheses: ROUND((0+0)/0\*100

While using this calculation:

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

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

I suspect my problem is related to {{#lookupIssues}} but not 100% sure.


author: Dick
body: Hi Gilad

Thanks for elaborating a bit on the problem you're facing, makes it easier :)

The error is about parenthesis not matching (and message you post clearly has a closing parenthesis missing).

Looking at your math line, there's a discrepancy too:

{{#=}}ROUND**( (**0+{{#lookupIssues}} double open

{{#if(equals(status.statusCategory.name,"Done"))}}+ double open double closed

{{/}}{{/}}0**)** single closed

/{{lookupIssues.Story points.sum\|0}}\*100{{/}}

So I suggest removing the one surplus parenthesis after the word ROUND.

hope this helps,

Dick


author: Dick
body: I now notice that Bill's line also seemed to be missing a closing parenthesis.

With all the curly braces and parentheses, this can easily happen. So it's best to check using the above method to see if there is consistency in your formula's.


Tags: cloud

jira-cloud