Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Worklog deletion and time spent adjustment

Hi all,
I'm trying to do a simple thing: I want t delete all the worklogs created in a set timeframe.
To do this, I'm trying to use this code

def projectKey = 'TEST'
def startDate = '2020/12/01'
def endDate = '2021/01/09'
queryText = "worklogDate >= '" +startDate+ "' AND worklogDate < '" + endDate + "' AND project = " + projectKey
//Executre the query
query = jqlQueryParser.parseQuery(queryText)
}catch(Exception ex){"Error executing the query: " + queryText)

def search =, query, PagerFilter.getUnlimitedFilter())

//Iterate the issues
search.results.each { documentIssue ->
MutableIssue issue = issueManager.getIssueObject(

def workLogManager = ComponentAccessor.getWorklogManager()
def logsForIssue = workLogManager.getByIssue(issue)

//Iterate the worklog of the issue
for(Worklog worklog : logsForIssue)
def date = new SimpleDateFormat("yyyy/MM/dd").format(worklog.getCreated())
if((date >= startDate) && (date < endDate)){
//Delete the worklog
workLogManager.delete(worklog.getAuthorObject(), worklog, null, true)

The above code works fine when there's only one worklog to delete: the worklog is deleted and the time is correctly updated.

Things get different when an issue has 2 or more to be deleted. In this case I've found that:
the delete call deletes correctly all the worklogs
the time spent field is being updated taking into account the latest worklog only

This is a real trial I've made using a sleep function after the delete call.
Initial situation:
worklog 1: 1 hour
worklog 2: 3 hours
worklog 4: 8 hours
time spent: 12 hours (1+3+8)

With the above code, the result is:
worklog 1 is deleted -> time spent 11 hours
worklog 2 is deleted -> time spent 9 hours
worklog 3 is deleted -> time spent 4 hours

So, from what I saw the time spent field is being reset every time at the initial value

1 answer


not that I am an expert in this area but might it be that the Issue itself is not getting updated in time after each worklog delete? Have you tried to implement a slight delay after each delete event to see if that resolves the problem?


Hi Alexander,
I tried both: adding a 10 seconds delay and updating the issue on each cycle. Unfortunately, it's still not working as expected.


Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Announcing the waitlist for Jira Work Management

Hey there Cloud Community members! We’re excited to give you the first glimpse of the new home for business teams on Jira — Jira Work Management. Jira Work Management is the next generation of J...

134 views 3 7
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you