How can I automate logging work hours into issues as they transition to "DONE"?
Asked by Anthony Amirfar:

I have some metrics that I'll need to report on weekly and rather then counting on individuals to manually log work into each task I'd like for this to be automated.

I've created a rule as follows

* Trigger: Transition to DONE from four other status
* Action: Log Work
  * Time Spent Field = {{now.diff(issue.created).hours}}
  * Date Started Field = {{issue.created}}

The rule thinks it has worked (mostly) but does not actually log any work in the task.

![logworkbug.png](https://community.atlassian.com/t5/image/serverpage/image-id/327031i6AE5C0DFD6797F67/image-size/large?v=v2&px=999 "logworkbug.png")![logworkrule.png](https://community.atlassian.com/t5/image/serverpage/image-id/327032iB39F91431F24315D/image-size/large?v=v2&px=999 "logworkrule.png")


Answers:
author: Bill Sheboy
body: Hi [@Anthony Amirfar](/t5/user/viewprofilepage/user-id/4991015)

First, please try adding the units of measure for hours to the end when you log that time:

```
{{issue.created.diff(now).hours}}h
```

If that does not help, please add the Log action (not the Log Work one again) to your rule to write out that expression. Then re-test to observe if it has the value you expected in the audit log details.

Kind regards,  
Bill

comments: author: Anthony Amirfar
body: Hi [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) ,

Thank you for your response.

I have tried both suggestions and unfortunately neither have solved my issue.

When using the "Log action" is this action supposed to be able to change fields within the issue? In this specific case my intent is to have the "Time tracking" populated with the total hours from creation to closure. Similar to when you manually log work in the issue by clicking the three dots then log work and entering "5h" for example.

The inputs I have tried for the "Log action" action are

Time tracking is {{now.diff(issue.created).hours}}h

Log work is {{now.diff(issue.created).hours}}h![aaaaaaaa.png](https://community.atlassian.com/t5/image/serverpage/image-id/327217iCCF0AC581C1D73DB/image-size/large?v=v2&px=999 "aaaaaaaa.png")


author: Bill Sheboy
body: Please add the log action to your rule, run the rule to test it, and the post an image of the audit log details.

And, please try reversing the values as time logged cannot be negative:

```
{{issue.created.diff(now).hours}}h
```


author: Anthony Amirfar
body: I'm getting a positive value in the log but no update is being made to the ticket itself. Is this action designed to simply return a value in the log and not actually change the "time tracking" field in the ticket as I am intending?

Thanks again for your help!

![auditlog1.png](https://community.atlassian.com/t5/image/serverpage/image-id/327242iD61294E19125E7F5/image-size/large?v=v2&px=999 "auditlog1.png")![log work rule1.png](https://community.atlassian.com/t5/image/serverpage/image-id/327243i6C9C156952800B8F/image-size/large?v=v2&px=999 "log work rule1.png")


author: Bill Sheboy
body: Ah, you also need to Log Work after that write to the audit log :\^)

Please re-add your Log Work action, with the smart value:

```
{{issue.created.diff(now).hours}}h
```

Writing to the audit log helps to diagnose rule problems / see progress, but does not update any issues.


author: Anthony Amirfar
body: That makes sense.

With that change the time is being logged into the ticket as intended!!!