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
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.
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)
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.