Logged time not decreasing after deleting worklog

Hi everyone,
I have imported worklogs in JIRA (JSON importer) on different issues and there has been a mistake which requires us to delete all of them.
I have prepared a script to do that but when the worklogs get deleted, the time spent (Logged - on Time tracking panel) doesn't decrease.
I've done some tests and this only happens for the worklogs imported in JIRA. Worklogs created manually and deleted with the same script don't cause any problems. The imported worklogs deleted manually work ok too.
What is surprising is that when I run the delete worklog, I get in the activity list exactly what I should, including "Removed the Worklog Time Spent".
Just for the completeness of the information, for the delete, I am using the JIRA API Interface WorklogManager

com.atlassian.jira.issue.worklog:
boolean delete(com.atlassian.crowd.embedded.api.User user,
             Worklog worklog,
             Long newEstimate,
             boolean dispatchEvent)

It's not that I have a problem with the script, it IS working. Deletes the worklogs. Is there more that needs to be done?

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.worklog.WorklogManager;
import com.atlassian.jira.issue.worklog.WorklogImpl;
import com.atlassian.jira.issue.worklog.Worklog;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;

WorklogManager worklogManager =  ComponentAccessor.getWorklogManager();
Issue issue = ComponentAccessor.getIssueManager().getIssueObject("EPIC-3101");
Long newEstimate;
//take the issue and for each worklog, delete it (complete clean-up)
worklogManager.getByIssue(issue).each { WorklogImpl worklog ->
    //to get the remaining there was before this worklog
	newEstimate = issue.getEstimate()+worklog.getTimeSpent()
    worklogManager.delete(ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser(), worklog, newEstimate, false)
    
}

The activity is interesting, because for the same one script run it is one of these three (not same):

image2015-5-15 14:46:24.png

out of which only the last one seems correct. I logged something? Seriously, by deleting a worklog?

If you have any idea what might be happening here, please let me know. Thanks a lot.

1 answer

0 vote

WorklogManager gives you an option to adjust the remaining estimate and time spent when the worklog is deleted. And you are updating those fields in your code.

If you want JIRA to auto adjust those values when the worklog is deleted, use WorklogService. See deleteAndAutoAdjustRemainingEstimate method.

Hi Jobin, thank you for the suggestion, I will immediately have a look at that. I am adjusting only the remaining estimate though, not touching the time spent, only reading it on the worklog itself. I thought that the logged time has nothing to do with estimates and that it will get auto-adjusted whatever you are using to delete a worklog. It gets deleted, so detract.

It is only adjusting the remaining estimate in the screenshot (to 4 hours. i.e 3+1). Timespent is reduced by the deleted worklog (3 hours). Anyways, WorklogService should do it for you.

Well yes, that is actually the point : "Timespent is reduced by the deleted worklog (3 hours)". It says so, but it doesn't DO that. I delete all of the worklogs and the Logged time remains the same. So I have 5 weeks logged on the issue with no worklog in the end. I will try the service though.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

708 views 6 13
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you