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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,316 views 14 20
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot