Hello, I need to record in a field (to later perform calculations) the time logged on the subtasks associated with an epic when the epic is closed.
For example:
subtask1 = 1h,
subtask2 = 1h,
Then in the epic ticket, have a field showing 2h.
Would it be possible to do this with an automation? How would it be done?
Any help on this matter would be greatly appreciated.
Thank you very much.
hi @Álvaro Boza
Hi @Álvaro Boza
Because you only need this in one space/project and you want a numeric value stored on the Epic when it’s closed (so you can use it later for calculations), the best practice is:
Use Automation to roll up values from issues that are actually in the Epic (true Epic children).
If you also need to include issues from other projects that are only linked (Relates/Blocks/etc.), Automation becomes unreliable for aggregation, that’s where ScriptRunner is the better tool.
1) Best practice (Automation) works for Epic children (even cross-project, if they’re in the Epic)
You want a field on the Epic that shows:
Deviation = Logged time / Estimated time
Example: estimated 2h, logged 1h → 0.5
Create custom field(s)
On the Epic, create a Number custom field, e.g.:
Time deviation (Logged / Estimate)
(Optional but helpful for transparency/debugging)
Epic total logged hours (calc) (Number)
Epic total estimated hours (calc) (Number)
Automation rule (runs on Epic closure)
Trigger: Issue transitioned → Done/Closed
Condition: Issue type = Epic
Action: Lookup issues (get the Epic’s child issues)
JQL (works in many Cloud sites):
parentEpic = {{issue.key}}
Then: Edit issue fields (on the Epic)
Epic total logged hours (calc):
{{lookupIssues.timespent.sum.divide(3600)}}
Epic total estimated hours (calc):
{{lookupIssues.timeoriginalestimate.sum.divide(3600)}}
Time deviation (Logged / Estimate):
{{#if(lookupIssues.timeoriginalestimate.sum)}}
{{lookupIssues.timespent.sum.divide(lookupIssues.timeoriginalestimate.sum)}}
{{else}}
0
{{/}}
This will store 0.5 for your example (1h logged / 2h estimated).
Important note for your “linked tickets from other projects”
If those company-managed tickets are true Epic children (i.e., they belong to the Epic), they’ll be included by the lookup even if they’re in a different project.
If they are only connected via issue links (relates to/blocks/etc.), they will not be included by the Epic children lookup and Cloud automation isn’t great at summing worklogs across arbitrary linked-issue sets.
2) If you must include linked issues (not Epic children): use ScriptRunner
Since you do have access to ScriptRunner, that’s the right tool if you need:
Epic children plus
issues linked from other projects (and optionally their sub-tasks)
With ScriptRunner you can:
collect Epic children
collect linked issues (by link type)
sum timespent and timeoriginalestimate
compute timespent / timeoriginalestimate
write the result into your Epic custom field when the Epic transitions to Done
For your case:
Start with the Automation rule above and make sure the work items you want included are in the Epic (that’s the cleanest and most maintainable on Cloud). Only reach for ScriptRunner if you truly need to aggregate time from linked-only issues across projects.
Hello @Arkadiusz Wroblewski !!!
Thank you very much for your help.
I just tested the automation and the following error occurred:
I’m attaching a screenshot of the automation rule:
Would I be missing anything else?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The error happens because “Time deviation” is a Number field, but the value your rule is trying to write is not being interpreted as a number at runtime (often because one of the source smart values is empty/null, or the calculation is evaluated as text).
To fix it, make sure your “Time deviation” edit uses a math block and converts inputs to numbers with a safe default:
In the “Edit work item fields → Time deviation” action, set:
{{#=}}
({{issue.customfield_<logged>.asNumber|0}}) - ({{issue.customfield_<estimated>.asNumber|0}})
{{/}}
Replace <logged> with the custom field id for Epic total logged hours
Replace <estimated> with the custom field id for Epic total estimated hours
.asNumber forces numeric conversion
|0 prevents failures when one of the fields is empty
If you are using “Lookup work items”
Because your rule does Lookup work items, you probably want the deviation based on the sum of the looked-up items. Then set:
{{#=}}
({{lookupIssues.customfield_<logged>.sum.asNumber|0}}) - ({{lookupIssues.customfield_<estimated>.sum.asNumber|0}})
{{/}}
Why it fails even though it shows “0”
Automation can still throw “cannot convert to number” if the expression actually evaluates to something like empty string, null, or text, even if the UI preview ends up showing “0”.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think the problem is with the summation of the task hours. I tried this variant that works with just 'issue' in another automation, but it doesn’t pick up any data—it returns 0: {{lookupIssues.timetracking.timeSpentSeconds.sum.asNumber|0}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
It finally worked with this:
{{#=}}{{lookupIssues.timetracking.timeSpentSeconds.sum}} / 3600{{/}}
Thank you so much for your help!
Best regards,
Álvaro
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great to hear that :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Álvaro Boza ,
You can do this by creating a scripted fields, using Script Runner app.
You will loop through all epic children and sum up their logged time into this scripted field that will always display the total.
The good thing is that it works for future and already existing epics/children.
Regards,
Petru
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Álvaro Boza ,
On the left hand menu look for Scripted fields.
You will need to create a script that will be executed when the field renders.
For that you will need to add your field to screen -> screen scheme -> issue type screen scheme -> Project.
Script Runner provides you wihe examples how to code your script.
Regards,
Petru
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Álvaro Boza
Welcome to the Atlassian community.
Do you really mean Subtask type work items, or do you mean the child items of the Epic? Subtasks cannot typically be directly connected to the Epic, but are instead children of standard work items that are children of the Epic.
Do you want to update this field as time is added to the items, or do you want to set it once only when the Epic is closed?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Trudy!! Thank you very much for your reply!!
Exactly, I meant the Epic’s child items, the Tasks, not the Subtasks.
I need it to be done once the Epic is closed, not as time is added.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Álvaro Boza
If you don't have the ScriptRunner app (suggested by @Petru Simion _Simitech Ltd__ ) then you could do this with an Automation Rule.
Are you familiar with Automation Rules?
Does this need to be executed for Epics in more than one project/Space?
Are the project/Space types where this is needed Team-managed or Company-managed?
Do you Epics have child items that are in different projects/Spaces than the Epic?
How do you want to see the data in the Epic? Do you want to see it in the Time Spent field so that it shows in the pretty format of weeks/days/hours?
There is no native custom field type for "duration" that will display time in that same manner. If you want to put the time into a number (or text) custom field and display it in the pretty format you would have to manipulate the summed time from the child issues to figure out how many minutes/hours/days/weeks it is, as the information is stored internally in seconds.
If you want it displayed in the Epic's Time Spent field, then in the rule you would use a Log Work action to log the time against the Epic. However that could lead to problems if the Epic is reopened and closed again at a later date.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.