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

Roberto Saltini December 2, 2016

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.

2 answers

2 votes
Leonard Chew
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 9, 2019

I'm having a similar issue on Jira Server 7.7.1 and Scriptrunner 5.5.7

I have the (simplified) Listener Script listed below. Lets say the script is triggered by the "Comment Edited" event (can be any other event).

The script will...
1)... correctly log the work and correctly update the timeSpent on the issue, if the event is fired by the native action of editing the Comment.
2)... correctly log the work, but NOT update the timeSpent, if the event "Comment Edited" is fired by a Workflow-Transition.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.worklog.WorklogImpl2

def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def worklogManager = ComponentAccessor.getWorklogManager()
def mutableIssue = issueManager.getIssueObject(event.issue.getId())


def worklog = new WorklogImpl2(mutableIssue, null, user.name, "My Comment", new Date(), null, null,3600, null)
worklogManager.create(user, worklog, 0, false)

 

Leonard Chew
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2019

This is a slightly different use case and effects all native fields.

It can be viewed here https://community.atlassian.com/t5/Jira-questions/Scriptrunner-Script-not-updating-native-fields-when-triggerd-by/qaq-p/1128707

2 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 9, 2016

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
TAGS
AUG Leaders

Atlassian Community Events