How to use automation to sum up in EPIC the hours logged in child tickets ?
Asked by Pierre Allard:

Hello all !

I'd like to do exactly what the title says.

So according to the details from this article <https://community.atlassian.com/t5/Automation-articles/How-to-sum-up-logged-hours-using-automation-in-Jira-Cloud/ba-p/1409115>

I've set up the rule below:

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

But in "Audit Log" I got error below :  
* Log work
  * Error trying to log work against an issue
  * Worklog must not be null., You must indicate the time spent working. (timeLogged)

Then I've tried the to set up the rule below

![Capture d??cran 2022-02-24 100046.png](https://community.atlassian.com/t5/image/serverpage/image-id/185149iAC7126A4D0A7ACDA/image-size/large?v=v2&px=999 "Capture d??cran 2022-02-24 100046.png")

But I've the same error.

Do you happen to have an idea of the problem ?

Thanks a million in advance for your help !

Pierre.


Answers:
author: Stefan Salzl
body: Hi [@Pierre Allard](/t5/user/viewprofilepage/user-id/4030553) ,

As the article mentioned in your question already points out: it?s not that straight forward with epics. Issues within an epic can not be pointed at directly via "child" connection.

In case it?s about stories/issues directly in an epic I solved this with a "lookup issues action" in between --\> see screenshot

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/185211iAE7846AFB57C2C3A/image-dimensions/230x460?v=v2 "image.png")

Please let me know if this helps.

Best  
Stefan

comments: author: Pierre Allard
body: Hello Stefan,

Here's what I did in my rule and that works very well ! :)

![Capture d??cran 2022-02-24 161439.png](https://community.atlassian.com/t5/image/serverpage/image-id/185221i5E5F13264912A098/image-dimensions/215x146?v=v2 "Capture d??cran 2022-02-24 161439.png")

Thanks a lot for your help!

Best.

Pierre.


author: Stefan Salzl
body: You are welcome [@Pierre Allard](/t5/user/viewprofilepage/user-id/4030553)

Please be so kind and accept the answer in order to this question appears solved which helps other users in need for the same information find that solution more easily ;)

Best  
Stefan


author: Brinda Tailor
body: [@Pierre Allard](/t5/user/viewprofilepage/user-id/4030553)

Can you please let me know what you wrote in the Date started field?

Thanks,

Brinda

![Screenshot 2022-07-14 145142.png](https://community.atlassian.com/t5/image/serverpage/image-id/206114iB27BF0A2475EBDD9/image-size/large?v=v2&px=999 "Screenshot 2022-07-14 145142.png")


author: Erika Simon
body: I have the same question. I believe it's {{now}} based on [Pierre Allard](https://community.atlassian.com/t5/user/viewprofilepage/user-id/4030553)'s [Feb 24, 2022](https://community.atlassian.com/t5/Automation-questions/How-to-use-automation-to-sum-up-in-EPIC-the-hours-logged-in/qaq-p/1954914)'s screen shot above, but I still can't get it working.


author: Hila Ben Halevi
body: Hi [@Stefan Salzl](/t5/user/viewprofilepage/user-id/4022685) ,

colud you please instruct me ho


author: Stephan Hannach
body: To complete this post: the feature request for this function: <https://jira.atlassian.com/browse/JSWCLOUD-17275>


author: kasimv_webelight
body: Hello all!  
I just want to do the sum of all user work logs for tasks, sub-tasks, bugs, and improvements for the last week. trigger this event on Saturday and this should be for all the users inside my Jira and send this sum of individual user work logs and send the message to individual users on Slack. so is it possible to use Jira automation?


author: Yatish Madhav
body: Thanks for the post and the comments, all.

I have noticed many articles like this BUT it seems either something is missed or it is flying over my head :D

With trigger Work logged for all operations, does the update or delete of task worklogs reflect on the Epic? I noticed that if it is updated, the new time is added to the epic and if existing worklog is deleted, that same time is added to the Epic. Both of these seem incorrect. Also, it does not look like we can identify if it is added , updated or deleted.

Any idea please?

comments: author: Yatish Madhav
body: Here is a screen grab. The add work log, update work log and delete work log all log the time additionally to the Epic where it should actually add/update/delete accordingly. i.e expecting the Epic to have the same work log total as the child issues, but the Epic simple appends the total that is added, updated and delted as well.

Hope that helps in helping me :)

![Screenshot from 2023-10-10 17-10-31.png](https://community.atlassian.com/t5/image/serverpage/image-id/285440i4E73713E7CA0792F/image-size/large?v=v2&px=999 "Screenshot from 2023-10-10 17-10-31.png")

Thank you


author: Hila Ben Halevi
body: Hi [@Stefan Salzl](/t5/user/viewprofilepage/user-id/4616993) ,

Could you please instruct me how to sum up to epic the time spent with brunch or rest API, as you mentioned above?

Thanks,

Hila.


author: silfarney_zanatta
body: Hi Guys,

Do you know How do it for Jira Data Center?

comments: author: Slava Gefen
body: Hey [@silfarney_zanatta](/t5/user/viewprofilepage/user-id/1291953) , is your need still relevant?

Do you have Scriptrunner?

With kind regards  
Slava


author: silfarney_zanatta
body: Hi [@Slava Gefen](/t5/user/viewprofilepage/user-id/4704947) ,

Yes, I still need a solution and I have Scriptrunner.

Let me know your feedback.

Thanks in advance!


author: Slava Gefen
body: Hey [@silfarney_zanatta](/t5/user/viewprofilepage/user-id/1291953) , great!

The last question! Do you want to sum up logged work in additional field, e.g. called Sum of Worklog, or do you want to use Native Worklog in Epics and make read-only?


author: silfarney_zanatta
body: I would like add this information in Native Field "Worklog".

But I think that is better use a custom field if us will use Scriptrunner, right?


author: Slava Gefen
body: Hey [@silfarney_zanatta](/t5/user/viewprofilepage/user-id/1291953) sorry for the delay.  
I thought we could do without Scriptrunner, if you need to implement it in new issues. If some stories already have worklog, firstly we need to update Epics with actual data.

So it turned out that the Automation is pretty simple:

1. We start from Work Logged action

![Capture1.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/261445iD732DCEA14505B3A/image-size/large?v=v2&px=999 "Capture1.JPG")

2. Then we check that Epic exists

![Capture2.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/261446iBD74A1D5ADDFA4DE/image-size/large?v=v2&px=999 "Capture2.JPG")

3. Then we go to Epic

![Capture3.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/261447iA4AB4EFA80D4CCEF/image-size/large?v=v2&px=999 "Capture3.JPG")

4. And finally add to Epic Work log that just was added to a Story

![Capture4.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/261448iA3810E8E8D07569D/image-dimensions/252x327?v=v2 "Capture4.JPG")![Capture5.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/261449iD32421D4B9FA6883/image-dimensions/477x294?v=v2 "Capture5.JPG")

After that in Epic worklog will be adjusted each time work logged in any Story:  

![Capture6.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/261451i42F611525FD3139B/image-size/large?v=v2&px=999 "Capture6.JPG")

You just need to think if worklog is updated or deleted. In this case we can implement if-else condition.

Let me know if it's working for you ?

With kind regards  
Slava


author: Slava Gefen
body: [@silfarney_zanatta](/t5/user/viewprofilepage/user-id/1291953) and I forgot to mention, that you need provide work log permissions in Epic only for Automation user, if you don't want users to put worklogs in the epic by mistake.

Regards  
Slava


author: silfarney_zanatta
body: Thanks so Much [@Slava Gefen](/t5/user/viewprofilepage/user-id/4704947)

My last question, this solution will get only the Time Spent in Story right? (not get the information from Sub-task (belongs to story).

Note. I am using the Jira Data Center.


author: Slava Gefen
body: Hey [@silfarney_zanatta](/t5/user/viewprofilepage/user-id/1291953)
> My last question, this solution will get only the Time Spent in Story right?

Yep, it takes Worklogs from all Story level issues to Epic. Do you want to provide from Sub-tasks to Epic also?
> Note. I am using the Jira Data Center.

Yes, my screens are from DC ?

Regards  
Slava


author: Erika Simon
body: Hey, [@Slava Gefen](/t5/user/viewprofilepage/user-id/4704947) Thank you so much! I will try this -- does it work for Jira Software too? (I see you worked this up for Silfarney_zanatta, who uses Jira Data Center.) I definitely want to include from subtasks to epic also. Thank you again, I will try this if you think it works also for Jira Software!

Erika


author: Erika Simon
body: Scratch that, [@slava](/t5/user/viewprofilepage/user-id/219959)_Gefen. I was able to make Hugh Lampert's suggestions above work for me in Jira Software. Thank you!

Erika


author: silfarney_zanatta
body: Hey [@Slava Gefen](/t5/user/viewprofilepage/user-id/4704947) , yes I need get the information from ALL Stories and Sub-tasks.

Thanks again.


author: Slava Gefen
body: [@silfarney_zanatta](/t5/user/viewprofilepage/user-id/1291953) sorry for the delay!
> yes I need get the information from ALL Stories and Sub-tasks.

In this way which behavior you are expected when a worklog was added to a sub-task?

Do you want to add it to Sory's worklog and then go up and add to Epic's?

Or just go two levels up to Epic and add there?


author: Slava Gefen
body: [@Erika Simon](/t5/user/viewprofilepage/user-id/4910050) hey, yep in Cloud version it's much easier!

Regards  
Slava


author: silfarney_zanatta
body: Hi [@Slava Gefen](/t5/user/viewprofilepage/user-id/4704947) ,

In this way which behavior you are expected when a worklog was added to a sub-task?

\<Zanatta\> In My it is possible I see the Total of Worklog hours in Story + Sub-task (into Story. So my expectation is add the same view but in EPIC (get all worklog from Stories + Sub-tasks)

Do you want to add it to Story's worklog and then go up and add to Epic's?

\<Zanatta\> My expectation when a work log hours was added in a Story or Sub-Task, I would like show it in EPIC level. (So we have today this feature to show the Total of Worklog into Story (Story + Sub-Tasks)

Or just go two levels up to Epic and add there?

\<Zanatta\> In my case I dont need add Sub-Task worklog in Story (because we have it today) but I need add it in Epic Level.

Note: I would like do the similar solution that we have in Jira Cloud using ({{issue.childissue.timeSpent.++**sum**++ }}) . But it not works in Jira Data Center **\*.sum**

I don't know if you got my point above.

Thanks in advance!


author: Slava Gefen
body: Hey [@silfarney_zanatta](/t5/user/viewprofilepage/user-id/1291953) sorry for the delay I was away a little)
> I don't know if you got my point above.

I hope I did.

So, in the rule above ([This my comment](https://community.atlassian.com/t5/Automation-questions/How-to-use-automation-to-sum-up-in-EPIC-the-hours-logged-in/qaq-p/1954914#M7028))  

we need to change the first condition with **if-else** block:  

![Capture7.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/264103i6AD1CE3B99CA4DA3/image-size/large?v=v2&px=999 "Capture7.JPG")  

And put everything else under it.

Then in **else** block you need to put this condition:  

![Capture8.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/264104i1D882F60483D2019/image-dimensions/396x568?v=v2 "Capture8.JPG")  

![Capture9.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/264105i22FD569047A2087E/image-size/large?v=v2&px=999 "Capture9.JPG")

And then for the branch use JQL with this smart-value:  

![Capture10.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/264106i22839275F5B483B4/image-size/large?v=v2&px=999 "Capture10.JPG")  

For the worklog action use the same that we used in Story level.

Finally, you will see in Epic worklogs from Sub-tasks:  

![Capture11.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/264108i97602FE1BEB1BCBA/image-size/large?v=v2&px=999 "Capture11.JPG")  
![Capture12.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/264110iD2821CC000F4CD95/image-size/large?v=v2&px=999 "Capture12.JPG")  

Let me know if you have any question.

Hope it helps!  
With kind regards  
Slava


author: Fabio Esteves da Silva Manzoni
body: Hi [@Slava Gefen](/t5/user/viewprofilepage/user-id/4704947)

Can you help me please with this case below?

I did exactly the automation and it worked, but if I select a date different from the current one in the story it will set the current date in the epic. In automation I set the option "Copy Created from Trigger issue" and it still didn't solve the problem. Do you have any idea how to resolve this.

I confess that I also couldn't do the if-sel for the removal. Whenever I try it adds deleted value

Thank you very much. Fabio


author: Slava Gefen
body: Hey [@Fabio Esteves da Silva Manzoni](/t5/user/viewprofilepage/user-id/5406779) , hope you are doing well ?
> I did exactly the automation and it worked, but if I select a date different from the current one in the story it will set the current date in the epic. In automation I set the option "Copy Created from Trigger issue" and it still didn't solve the problem. Do you have any idea how to resolve this.

I'm not sure I understand your need. Could you please share some screenshots what are you trying to achieve?

Thanks in advance!  
Slava


author: Fabio Esteves da Silva Manzoni
body: Hi Slava,

Thank for your help, below are the prints.

I registered in the Story worklog January 30th at 9 AM. The automation worked, but in Epic it registered on February 2nd at 10:50.

Fabio![epic timesheet automation.png](https://community.atlassian.com/t5/image/serverpage/image-id/304361iBF2F721434B6822B/image-size/large?v=v2&px=999 "epic timesheet automation.png")![epic timesheet epic.png](https://community.atlassian.com/t5/image/serverpage/image-id/304360i0901821E14E6C3D5/image-size/large?v=v2&px=999 "epic timesheet epic.png")![epic timesheet story.png](https://community.atlassian.com/t5/image/serverpage/image-id/304359i5AEC6B6D0FB000C2/image-size/large?v=v2&px=999 "epic timesheet story.png")


author: Slava Gefen
body: Hey [@Fabio Esteves da Silva Manzoni](/t5/user/viewprofilepage/user-id/5406779)

What is your initial trigger?  
Maybe just put {{now}} smart-value as a 'Date Started' value to log the same date?

Thanks  
Slava


author: Fabio Esteves da Silva Manzoni
body: Hi [@Slava Gefen](/t5/user/viewprofilepage/user-id/4704947)

Setting the condition {{now}} in data started it takes the current system date and time and not the date and time selected by the user.

Thanks,

Fabio![automation configuration.png](https://community.atlassian.com/t5/image/serverpage/image-id/304612i75B652F86CD2764B/image-size/large?v=v2&px=999 "automation configuration.png")![log work epic.png](https://community.atlassian.com/t5/image/serverpage/image-id/304611i636237E2D39B0346/image-size/large?v=v2&px=999 "log work epic.png")![log work story 2.png](https://community.atlassian.com/t5/image/serverpage/image-id/304610i761954867BD57B6A/image-size/large?v=v2&px=999 "log work story 2.png")![log work story.png](https://community.atlassian.com/t5/image/serverpage/image-id/304613i1DA01BEA4607CA41/image-size/large?v=v2&px=999 "log work story.png")


author: Slava Gefen
body: Hey [@Fabio Esteves da Silva Manzoni](/t5/user/viewprofilepage/user-id/5406779) I got, a user can set the 'Started Date'

Then try please this smart-value ?

```
{{worklog.started}}
```

Thanks  
Slava


author: Fabio Esteves da Silva Manzoni
body: [@Slava Gefen](/t5/user/viewprofilepage/user-id/4704947)

Worked.

Thank you so much.

Fabio


author: Brellison
body: [@Pierre Allard](/t5/user/viewprofilepage/user-id/4030553) Have you come across the issue of the automation double counting time spent entries?  

For example, if I enter 1h of work on a task within an epic, the epic will show 1h. However, if I enter another 1h of work on that same task or another task within the epic, the epic shows 3h. Which makes me believe it counts the previous entries every time.

comments: author: Sehreen Jafry
body: [@Brellison](/t5/user/viewprofilepage/user-id/4647447) Running into the same issue here. Every time the automation runs, instead of 'over-writing', it adds a new worklog to the previous one hence adding to the previous value.  

One workaround would be to delete the previous worklog on epic level before running the rule.


author: Pierre Allard
body: Hi [@Brellison](/t5/user/viewprofilepage/user-id/4647447) [@Sehreen Jafry](/t5/user/viewprofilepage/user-id/4708332)

You're right, I've faced the same problem. But it seems that automation rule cannot delete worklogs...


author: Sehreen Jafry
body: [@Pierre Allard](/t5/user/viewprofilepage/user-id/4030553)   
Yeah so I ended up just manually deleted the previous worklog before running this particular automation rule.  

That's the only thing I can think of at the moment, till there can be a way to delete the worklog via automation first and then run the automation to sum up the logged hours and save on the EPIC level.


author: Hugh Lampert
body: Since the work log, IS a rolling work log and you can't delete existing entries through automation, the answer is to check if the sum of the timespent in the exisiting entries in the EPIC log equate to the sum of the timespent on all the child tasks before adding a new entry to the EPIC. If the time spent on the EPIC is less than the time spent on all the child tasks, add a new entry to the epic with the difference:

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


author: Jo?o Vitor Maur?cio de Abreu
body: Nice work [@Hugh Lampert](/t5/user/viewprofilepage/user-id/4898908)!

I would only divide by 3600 instead of 60, I think you're maybe logging in minutes when they should be in hours. I can't tell if that's how it should work for you because I use Tempo Timesheets, so I just changed this and it worked very well.


author: Pierre Allard
body: Thank you very much [@Hugh Lampert](/t5/user/viewprofilepage/user-id/4898908) , that works very well ! :)


author: Manish Bhardwaj
body: I am not using Jira cloud, its Jira Data Center. So there is no "LookupIssues". What's the alternative in that case?


author: Stefan Salzl
body: Hi [@Manish Bhardwaj](/t5/user/viewprofilepage/user-id/4085211)

depends on your specific requirement but in general I see 2 ways to do:

* creating a branch with a jql branch or
* add a "send webrequest" action that does a JQL

Best  
Stefan


author: Ilidio Faria
body: [@Hugh Lampert](/t5/user/viewprofilepage/user-id/4898908) do you mind to post the JQL of the automation in text were?


author: Erika Simon
body: [@Hugh Lampert](/t5/user/viewprofilepage/user-id/4898908)this is genius. But in the very last step (Then: Log work), what should be entered for the required field "Date Started"? Please see screen shot. It's not working for me, and I think it's because I don't know what to put into this field. ![log work date field.png](https://community.atlassian.com/t5/image/serverpage/image-id/252789iB2177BDA55041222/image-size/large?v=v2&px=999 "log work date field.png")


author: Hugh Lampert
body: Regarding what to put in the "Date Started" field:

The "date started" field can be left as "{{now}}".

If this isn't working for you and you have "{{now}}" in this field, then there is some other problem; check the evaluation log.


author: Erika Simon
body: Thanks [@Hugh Lampert](/t5/user/viewprofilepage/user-id/4898908) for your quick reply. Where will I find an evaluation log? I'm using {{now}} and it isn't working. I'm not getting any errors, but the time logged on children does not show up on epic.

UPDATE to my 4/19 note -- it's now working for me! Thank you so much, @Hugh_Lampert!


author: Ilidio Faria
body: [@Hugh Lampert](/t5/user/viewprofilepage/user-id/4898908) also not working were. Can you please export your automation to a JSON file? In my case you can find here the log![2023-04-20_09h16_48.png](https://community.atlassian.com/t5/image/serverpage/image-id/252905i6510F1C0232486CE/image-size/large?v=v2&px=999 "2023-04-20_09h16_48.png")


author: Ilidio Faria
body: [@Hugh Lampert](/t5/user/viewprofilepage/user-id/4898908) can you help with the issue above?


author: Slava Gefen
body: [@Manish Bhardwaj](/t5/user/viewprofilepage/user-id/4085211) hey ?
> I am not using Jira cloud, its Jira Data Center. So there is no "LookupIssues". What's the alternative in that case?

You can try my solution for DC above (Now it describes create worklog only).

Regards  
Slava


Tags: jira

time-spent