Have you detected that a lot of logs have been saved in an incorrect TASK? Have you tried to move it…

This post will help you to move it automatically using Scriptrunner.

Basically, instead of move, the code is doing a copy of logs and later, remove the previous ones.

KEEP CAREFULLY using this code! CONFIRM that the logs have been correctly copied before removing the previous ones.

I hope it helps!

Best regards.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.worklog.Worklog
import com.atlassian.jira.issue.worklog.WorklogImpl2
import com.atlassian.jira.issue.worklog.WorklogImpl
import com.atlassian.jira.security.roles.ProjectRoleManager

def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.getIssueManager()
def sourceIssue = issueManager.getIssueObject("origin task key")
def destinationIssue = issueManager.getIssueObject("destination task key")
def usersRole = projectRoleManager.getProjectRole("Users")
def worklogManager = ComponentAccessor.getWorklogManager()

//get worklogs for issue

def logsForSourceIssue = worklogManager.getByIssue(sourceIssue)
for(Worklog worklog : logsForSourceIssue)
       def new_worklog = new WorklogImpl(worklogManager,destinationIssue, null, worklog.getAuthorObject().getKey(), worklog.getComment().toString(),worklog.getStartDate() as Date, null, null,worklog.getTimeSpent() as Long)
        worklogManager.create(user, new_worklog, 0L, true)

def logsForDestinationIssue = worklogManager.getByIssue(destinationIssue)


Posted by:juanjomarchal

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s