You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
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
try{
query = jqlQueryParser.parseQuery(queryText)
}catch(Exception ex){
log.info("Error executing the query: " + queryText)
}
def search = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
//Iterate the issues
search.results.each { documentIssue ->
MutableIssue issue = issueManager.getIssueObject(documentIssue.id)
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
Hi,
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?
BR
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.
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.