Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automation - Summing up original estimate using linkedissues

Jeffrey_Denton
Contributor
January 22, 2025

I'm creating an automation that performs the following tasks:

On Trigger (manually), the automation is to sum up original estimate to an Epic custom field called Total Project Estimate.  The rule retrieves all child tasks linked to the epic using JQL.  It also retrives linked "Idea" issue to retrieve the original effort on the idea.  Then, it takes the values of all child tasks and the original estimate of the idea and sums them up to the custom field Total Project Estimate. 

The issue I'm having is that the calculation in the variable is mibehaving :D

When you look at the audit log you can see it clearly, but I'm banging my head trying to figure out the error of my ways.  

Here is the audit log and rule:

It looks like a variable issue:

screencapture-rk-industries-atlassian-net-jira-settings-automation-2025-01-22-13_22_29-edit.pngscreencapture-rk-industries-atlassian-net-jira-settings-automation-2025-01-22-13_23_13-edit (1).png

 

3 answers

2 accepted

1 vote
Answer accepted
Bill Sheboy
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.
January 22, 2025

Hi @Jeffrey_Denton 

Regarding automation branches and created variable scope, there are two key things to know:

  • When a variable is created before a branch on one-and-only-one-issue, and then updated inside of the branch by re-creating it with the same name, the update value is available after the branch.  This works because the branch is essentially converted to "in-line code" as if the branch was not present.
  • For branches on more-than-one-issue, none of that is possible.  Each pass through the loop is a new variable inside the branch, and it is thrown away after each loop step.  The reason is such branches are executed in parallel and asynchronously for performance, and there is no guarantee of processing order or even when the branch will complete.  Specifically, the steps in the rule appearing after the branch will likely start before the branch completes!

 

For your scenario, I recommend:

  • Instead of using the branch, use a second Lookup Issues action with JQL to gather the linked to issues
  • Sum the field from the Lookup Issues result, adding it to your total

Also...as your rule initializes that field to 0, remember to add a Re-fetch Issue action immediately after that step to reload the data.

Kind regards,
Bill

Jeffrey_Denton
Contributor
January 23, 2025

Bill, this worked very well.  I'm posting my automation so you can see how I solved it with your help. .  

Thanks, again, and again, and again.  screencapture-rk-industries-atlassian-net-jira-settings-automation-2025-01-23-07_12_34-edit.png

Like Bill Sheboy likes this
0 votes
Answer accepted
Marcos Defina
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.
January 22, 2025

Hi @Jeffrey_Denton

I'm not sure if I fully understand the final problem you are facing, please correct me if I'm wrong, but you were expecting to see 20 hours at the final results, right? 10 from Ideas 10 from child Total.

If that's the case, I would guess the problem is with declaring your ideaOriginalEstimate inside of the BranchLoop.

That's a long shot, but in normal programming languages, if you declare a variable inside of a loop or function, it often becomes inaccessible to the global scope of your code.

As Jira Automations is probably develop on similar principles, I would recommend you to create the Total Idea Hours variable before the Branch, test if it is accessible inside the branch afterwards, Create a second variable inside the Branch (current_IdeaHours - because you're looping through many ideas), then you add the value of the Total Idea Hours = Total Idea  Hours + current_IdeaHours.

This would ensure you are storing the values you calculated inside the loop in a scope greater than the loop.

hope it helps!

Jeffrey_Denton
Contributor
January 22, 2025

Sorry if I wasn't clear, Idea total is 5, and Child Totals 10 = 15.  

I'm going to step through your suggestion and see how to apply it here.  I feel like I have to declare it inside the branch, but maybe I don't.  hmmmm

Marcos Defina
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.
January 22, 2025

Oh I see! That's ok, the core of the problem I got - only the wrong numbers.
You see in the last message of your log, we can see 0 hours for idea - that's what made me believe whatever you're storing inside the loop, isn't getting accessed outside the loop.

Try as I suggested, one internal variable, one external - and during the loop, the external receives the value of the internal.

Hope it works!

Like Jeffrey_Denton likes this
Jeffrey_Denton
Contributor
January 23, 2025

you were right about declaring inside the bench loop.  You just can't do it! :D

Thank you for diving into this with me. 

Like Marcos Defina likes this
Marcos Defina
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.
January 24, 2025

Happy to help!

0 votes
Vishal Biyani
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.
January 22, 2025

@Jeffrey_Denton 

I am doing something similar i.e. summing up hours at epic level. I am relying on below function so that a loop on subtasks can be avoided. Save the calculated value in a smart variable and then editing the custom field in epic with the value set in smart variable.

{{#=}} {{lookupIssues.aggregatetimespent.sum}} / 3600 {{/}}

See if this helps you simply your workflow and fix the error that you are facing.

Jeffrey_Denton
Contributor
January 25, 2025

Thank you, Vishal.  I did get it to work

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events