Forums

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

Calculate difference on worklog edit

Kevin Grey April 29, 2022

Hi, is it possible to access the previous values of a worklog when someone edits them using the automation trigger "Work Logged". I am trying to pass the values on and for an edit I need to know that a user has changed from 2h down to 1h so that I can calculate this difference and send it to a downstream service.

I have tried logging the "{{changelog}}" but receive this "ChangeLogList{startAt=0, maxResults=0, total=0, histories=null}"

Also "{{#changelog.timeSpentSeconds}}{{fromString}} - {{toString}}{{/changelog.timeSpentSeconds}}" doesnt work. 

Is it possible to achieve this?

2 answers

1 accepted

2 votes
Answer accepted
Kevin Grey May 4, 2022

I created separate rules for CREATE, UPDATE and DELETE worklogs. CREATE and DELETE was easy to handle as that just adds or subtracts, the logic for UPDATE was a bit more complex and brittle.

Screen Shot 2022-05-04 at 1.19.06 PM.png

I ended up using the changelog from the API. It relies on the last value in there being the worklog that triggered the automation. This would have been a lot simpler if I had access to the changelog from a worklog triggered action

0 votes
Stefan Salzl
Community Champion
April 30, 2022

Hi @Kevin Grey 

I´m not getting the use case right now. Could you please further describe "from 2h down to 1h"? As far as I know the log work is just adding time to your work log. Or do you mean the the "Original estimate" field?

Best
Stefan

Kevin Grey May 3, 2022

Screen Shot 2022-05-03 at 11.21.24 AM.png

Example automation above. This works fine for sending newly created work logs, however when a user edits them I would like to know the before and after values. Currently I can only access the "after value"

Screen Shot 2022-05-03 at 11.25.18 AM.png

Stefan Salzl
Community Champion
May 3, 2022

Hi @Kevin Grey 

Couldn´t figure out how to do this out of the box.

Without knowing what you are trying to solve with it one way would be to calculate with the values you´ve got:

From the event you can get the amount of time that is added and the current spent time can be retreived from the issue. Subtracting the time added from time spent will give you the initial value.

Best
Stefan

Kevin Grey May 3, 2022

I considered this but if multiple people are logging against the ticket or if there are multiple logs from the same person then it would be difficult to calculate as I would also have to get all worklogs associated to that ticket and caluclate the total from them and then compare to the issue (whilst hoping that no-one has submitted another log in the meantime)

Stefan Salzl
Community Champion
May 3, 2022

What do you mean by saying "in the meantime"? The automation rule will immediatly fire as soon as a person logs work. So each time someone logs work it will calculate the amount of time spent before that person logged work.

As I mentioned in my last post: Without knowing the requirement/use case/problem that should be solved (from a functional perspective) we can only discuss technical implementations that might not really tackle the right thing 🤷‍♂️

Best
Stefan

Kevin Grey May 4, 2022

@Stefan Salzl my use case is that I'd like to be able to send the time logged against an issue by each user to a downstream service for timetracking and for that I need to calculate the time logged against that worklog. Create and Delete actions are fine but for updates I'd like to know what the initial value is, I've given a few scenarios below to help illustrate:

User creates a 2h worklog: send 2h to downstream service

User edits that work to be 3h: send 1h to downstream service

User edits that worklog again to be 1h: send -2h to downstream service

User deletes that worklog: send -1h to downstream service

 

Also, the above solution unfortunately doesnt work as I can't use the time logged against the issue because the rule runs after the worklog has been changed which means the issue has the updated value

Stefan Salzl
Community Champion
May 4, 2022

Hi @Kevin Grey 

Thanks for the examples. Got that logically.

As far as I understood worklog it is: someone works 1h on an issue, so loggs 1h (--> 1h is added), the next day 30m are logged (--> 30m added).

My questions are:

  • where and how are previously logged worktimes edited? and...
  • Why? (especially: what would be the use case of even deleting worklog?)

 

As far as my personal knowledge reaches unfortunately I can´t think of any out of the box solution that A4J is capable to do this as the worklog is a special event/trigger different to "field change".

Best
Stefan

Kevin Grey May 4, 2022

Moving response to answer section

Stefan Salzl
Community Champion
May 4, 2022

WOW!!!! That´s awesome. API was something that came to my mind but I do have too little knowledge of its capability and to really provide you a feasible solution 🙈

Great job man! Your solution looks awesome 🙌 I feel you. I don´t understand either why "worklog" does not appear as "value / field change" and cannot be covered by trigger action as such =S

Best
Stefan

Suggest an answer

Log in or Sign up to answer