Time Logged field is incorrectly updated when several worklogs are created via groovy

Hi,

I have written a post-function script to2 move all of the worklog entries from one issue to another. The worklog is correctly moved but the "Time logged fields of the two issues are not updated correctly. The "Time logged" field of the issue to where the work log is moved to is updated with only the value of the last worklog item moved whereas the "Time logged" field of the issue from where the work log entries are moved is updated like if all of the entries but not the last one where moved.

I am looking for either finding a bug in my code or find a workaround for a potential bug in JIRA.

I believe that the following example will provide a more clear picture of the issue.

For testing purpose, I have written the following script for console execution:

MutableIssue issue = CommonFunctions.getIssue("TASKTEST-304")
MutableIssue newIssue = CommonFunctions.getIssue("TASKTEST-305")

WorklogManager worklogManager = ComponentAccessor.getWorklogManager()

List<Worklog> workLogs = worklogManager.getByIssue(issue)
for(Worklog worklog in workLogs)
{
    WorklogImpl newWorklog = new WorklogImpl(
            worklogManager,
            newIssue,
            null,
            worklog.authorKey,
            worklog.getComment(),
            worklog.getStartDate(),
            worklog.getGroupLevel(),
            worklog.getRoleLevelId(),
            worklog.getTimeSpent()
    )

    worklogManager.create(worklog.getAuthorObject(),newWorklog,0L,true)
}

The following screenshots show the script execution effect on the two selected issues

 

ISSUE FROM WHICH THE WORKLOG IS MOVED BEFORE SCRIPT EXECUTION

Selezione_048.pngAs you can see 3 worklog entries have been logged to this issue: 1h, 2h and 4h.

 

ISSUE FROM WHICH THE WORKLOG IS MOVED AFTER SCRIPT EXECUTION

Selezione_049.png

As you can see, all of the worklog entries have been deleted, but the "Time Logged" field still shows 4h (correspondent to the total work time for the first two moved worklog entries) when it should show 0h

ISSUE TO WHICH THE WORKLOG IS MOVED AFTER THE SCRIPT EXECUTION

Selezione_050.png

As you can see, all of the worklog entries have been transferred, but the "Time Logged" field only shows the value for the last worklog entry when it should show 7h.

1 answer

This widget could not be displayed.

Looks like a JIRA bug to me. You can reproduce it with a simpler script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.worklog.WorklogImpl2
import java.util.concurrent.TimeUnit

def issue = ComponentAccessor.issueManager.getIssueObject("JRA-3")
def worklogManager = ComponentAccessor.getWorklogManager()
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

3.times {
    def worklog = new WorklogImpl2(issue, null, "admin", "foo", new Date() - 1, null, null, TimeUnit.HOURS.toSeconds(2), null)
    worklogManager.create(user, worklog, 0L, true)
}

Possibly relates to https://jira.atlassian.com/browse/JRA-31888. Try asking support.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

510 views 3 18
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